27
|
1 |
/*
|
|
2 |
* Copyright (c) 2002 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: MsgExpandableControlEditor implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// ========== INCLUDE FILES ================================
|
|
21 |
|
|
22 |
#include <eikappui.h> // for CEikAppUi
|
|
23 |
#include <eikenv.h> // for CEikonEnv
|
|
24 |
#include <txtrich.h> // for CRichText
|
|
25 |
#include <baclipb.h> // for CClipboard
|
|
26 |
#include <gulfont.h> // for TLogicalFont
|
|
27 |
#include <AknUtils.h> // for AknUtils
|
|
28 |
#include <barsread.h> // for TResourceReader
|
|
29 |
#include <ItemFinder.h> // for automatic highlight
|
|
30 |
|
|
31 |
#include <AknUtils.h>
|
|
32 |
#include <AknsUtils.h>
|
|
33 |
#include <AknSettingCache.h>
|
|
34 |
#include <AknsConstants.h>
|
|
35 |
#include <applayout.cdl.h> // LAF
|
|
36 |
#include <aknlayoutscalable_apps.cdl.h>
|
|
37 |
#include <aknlayoutscalable_avkon.cdl.h>
|
|
38 |
#include <AknsFrameBackgroundControlContext.h> // FrameBackgroundControlContext
|
|
39 |
#include <AknsDrawUtils.h>
|
|
40 |
|
|
41 |
#include "MsgEditorCommon.h" //
|
|
42 |
#include "MsgExpandableControlEditor.h" // for CMsgExpandableControlEditor
|
|
43 |
#include "MsgExpandableControl.h" // for CMsgExpandableControl
|
|
44 |
#include "MsgBaseControl.h" // for TMsgEditPermissionFlags
|
|
45 |
#include "MsgBaseControlObserver.h" // for MMsgBaseControlObserver
|
|
46 |
#include "MsgEditorPanic.h" // for MsgEditor panics
|
|
47 |
#include "MsgEditorLogging.h"
|
|
48 |
#include "MsgEditorCustomDraw.h" // for CMsgEditorCustomDraw
|
|
49 |
|
|
50 |
// ========== EXTERNAL DATA STRUCTURES =====================
|
|
51 |
|
|
52 |
// ========== EXTERNAL FUNCTION PROTOTYPES =================
|
|
53 |
|
|
54 |
// ========== CONSTANTS ====================================
|
|
55 |
|
|
56 |
// ========== MACROS =======================================
|
|
57 |
|
|
58 |
// ========== LOCAL CONSTANTS AND MACROS ===================
|
|
59 |
// OPEN:
|
|
60 |
const TInt KEdwinTopMargin = 0;
|
|
61 |
const TInt KEdwinBottomMargin = 0;
|
|
62 |
const TInt KEdwinLeftMargin = 0;
|
|
63 |
const TInt KEdwinRightMargin = 0;
|
|
64 |
const TInt KExpFullFormattingLength = 500;
|
|
65 |
|
|
66 |
// ========== MODULE DATA STRUCTURES =======================
|
|
67 |
|
|
68 |
// ========== LOCAL FUNCTION PROTOTYPES ====================
|
|
69 |
|
|
70 |
// ========== LOCAL FUNCTIONS ==============================
|
|
71 |
|
|
72 |
// ========== MEMBER FUNCTIONS =============================
|
|
73 |
|
|
74 |
// ---------------------------------------------------------
|
|
75 |
// CMsgExpandableControlEditor::CMsgExpandableControlEditor
|
|
76 |
//
|
|
77 |
// Constructor.
|
|
78 |
// ---------------------------------------------------------
|
|
79 |
//
|
|
80 |
EXPORT_C CMsgExpandableControlEditor::CMsgExpandableControlEditor(
|
|
81 |
TUint32& aFlags,
|
|
82 |
MMsgBaseControlObserver* aBaseControlObserver)
|
|
83 |
:
|
|
84 |
CEikRichTextEditor( TGulBorder::ENone ),
|
|
85 |
iFlags( aFlags ),
|
|
86 |
iBaseControlObserver( aBaseControlObserver )
|
|
87 |
{
|
|
88 |
}
|
|
89 |
|
|
90 |
// ---------------------------------------------------------
|
|
91 |
// CMsgExpandableControlEditor::CMsgExpandableControlEditor
|
|
92 |
//
|
|
93 |
// Constructor.
|
|
94 |
// ---------------------------------------------------------
|
|
95 |
//
|
|
96 |
EXPORT_C CMsgExpandableControlEditor::CMsgExpandableControlEditor(
|
|
97 |
const CCoeControl* aParent,
|
|
98 |
TUint32& aFlags,
|
|
99 |
MMsgBaseControlObserver* aBaseControlObserver )
|
|
100 |
:
|
|
101 |
CEikRichTextEditor( TGulBorder::ENone ),
|
|
102 |
iParentControl( aParent ),
|
|
103 |
iFlags( aFlags ),
|
|
104 |
iBaseControlObserver( aBaseControlObserver ),
|
|
105 |
iFindItemEventReceived( EFalse )
|
|
106 |
{
|
|
107 |
}
|
|
108 |
|
|
109 |
// ---------------------------------------------------------
|
|
110 |
// CMsgExpandableControlEditor::~CMsgExpandableControlEditor
|
|
111 |
//
|
|
112 |
// Destructor.
|
|
113 |
// ---------------------------------------------------------
|
|
114 |
//
|
|
115 |
EXPORT_C CMsgExpandableControlEditor::~CMsgExpandableControlEditor()
|
|
116 |
{
|
|
117 |
delete iItemFinder;
|
|
118 |
delete iFrameBgContext;
|
|
119 |
delete iCustomDraw;
|
|
120 |
}
|
|
121 |
|
|
122 |
// ---------------------------------------------------------
|
|
123 |
// CMsgExpandableControlEditor::ConstructL
|
|
124 |
//
|
|
125 |
// Constructs and initializes this editor.
|
|
126 |
// ---------------------------------------------------------
|
|
127 |
//
|
|
128 |
EXPORT_C void CMsgExpandableControlEditor::ConstructL()
|
|
129 |
{
|
|
130 |
TInt edwinFlags = ENoHorizScrolling |
|
|
131 |
ENoAutoSelection |
|
|
132 |
EWidthInPixels |
|
|
133 |
EAllowUndo |
|
|
134 |
EResizable |
|
|
135 |
EPasteAsPlainText;
|
|
136 |
|
|
137 |
iFlags = EMsgControlModeDoNotDrawFrameBgContext;
|
|
138 |
ResolveLayouts();
|
|
139 |
|
|
140 |
/*if ( iBaseControlObserver &&
|
|
141 |
!iBaseControlObserver->ViewInitialized() )
|
|
142 |
{
|
|
143 |
SetSuppressFormatting( ETrue );
|
|
144 |
}*/
|
|
145 |
|
|
146 |
TInt numberOfLines( 0 );
|
|
147 |
|
|
148 |
if ( iFlags & EMsgControlModeSizeFixedToOneLine )
|
|
149 |
{
|
|
150 |
// make control fixed size and allow horizontal scrolling.
|
|
151 |
edwinFlags &= ~EResizable;
|
|
152 |
edwinFlags &= ~ENoHorizScrolling;
|
|
153 |
numberOfLines = 1;
|
|
154 |
}
|
|
155 |
|
|
156 |
CEikRichTextEditor::ConstructL(
|
|
157 |
iParentControl,
|
|
158 |
numberOfLines,
|
|
159 |
iMaxNumberOfChars,
|
|
160 |
edwinFlags );
|
|
161 |
|
|
162 |
// Emoticon support for MMS Subject field
|
|
163 |
AddFlagToUserFlags(EAvkonEnableSmileySupport);
|
|
164 |
|
|
165 |
// Both global text editor and edwin have it's own formatting layers.
|
|
166 |
// CEikRichTextEditor::ConstructL call will set global formatting layers
|
|
167 |
// into use for text. This is not correct as edwin formatting layers
|
|
168 |
// will hold correct formatting values. Below calls will set edwin
|
|
169 |
// formatting layers into use and prevent client based formatting from
|
|
170 |
// being based on incorrect formatting layer.
|
|
171 |
SetParaFormatLayer( iEikonEnv->SystemParaFormatLayerL()->CloneL() );
|
|
172 |
SetCharFormatLayer( iEikonEnv->SystemCharFormatLayerL()->CloneL() );
|
|
173 |
|
|
174 |
SetUpperFullFormattingLength( KExpFullFormattingLength );
|
|
175 |
|
|
176 |
SetMaximumHeight( MsgEditorCommons::MaxBodyHeight() );
|
|
177 |
|
|
178 |
// Set the wrap width to be that of the current header text pane.
|
|
179 |
// This will make the formatting of text safer if it is performed
|
|
180 |
// before the editor has ever had SetSize() called. WrapWidth is
|
|
181 |
// usually set in HandleSizeChanged()
|
|
182 |
if ( iLayout )
|
|
183 |
{
|
|
184 |
iLayout->SetWrapWidth( iTextLayout.TextRect().Width() );
|
|
185 |
}
|
|
186 |
|
|
187 |
// TODO: Get from LAF or something... Currently
|
|
188 |
// all of these are zero. OK?!
|
|
189 |
TMargins8 edwinMargins;
|
|
190 |
edwinMargins.iTop = KEdwinTopMargin;
|
|
191 |
edwinMargins.iBottom = KEdwinBottomMargin;
|
|
192 |
edwinMargins.iLeft = KEdwinLeftMargin;
|
|
193 |
edwinMargins.iRight = KEdwinRightMargin;
|
|
194 |
SetBorderViewMargins( edwinMargins );
|
|
195 |
|
|
196 |
iBgContext = AknsDrawUtils::ControlContext( this );
|
|
197 |
|
|
198 |
// NOTE: iItemFinder can be created by derived class if needed.
|
|
199 |
}
|
|
200 |
|
|
201 |
// ---------------------------------------------------------
|
|
202 |
// CMsgExpandableControlEditor::ConstructFromResourceL
|
|
203 |
// ---------------------------------------------------------
|
|
204 |
//
|
|
205 |
EXPORT_C void CMsgExpandableControlEditor::ConstructFromResourceL(
|
|
206 |
TResourceReader& aReader )
|
|
207 |
{
|
|
208 |
// This used to be font id. Not used anymore. Have to read it, though.
|
|
209 |
/*TInt fontId =*/ aReader.ReadInt32();
|
|
210 |
|
|
211 |
ConstructL();
|
|
212 |
|
|
213 |
if ( !IsReadOnly() )
|
|
214 |
{
|
|
215 |
ReadAknResourceL( aReader );
|
|
216 |
}
|
|
217 |
}
|
|
218 |
|
|
219 |
// ---------------------------------------------------------
|
|
220 |
// CMsgExpandableControlEditor::SetAndGetSizeL
|
|
221 |
//
|
|
222 |
// Sets size for this editor. Height of given size aSize may change if the
|
|
223 |
// editor contains text.
|
|
224 |
// ---------------------------------------------------------
|
|
225 |
//
|
|
226 |
EXPORT_C void CMsgExpandableControlEditor::SetAndGetSizeL( TSize& aSize )
|
|
227 |
{
|
|
228 |
TSize controlSize( aSize.iWidth, aSize.iHeight );
|
|
229 |
|
|
230 |
if( TextLayout() && TextLayout()->IsFormattingBand() )
|
|
231 |
{
|
|
232 |
// Partial formatting on-going -> needs whole body height
|
|
233 |
//controlSize.iHeight = MaximumHeight();
|
|
234 |
}
|
|
235 |
else
|
|
236 |
{
|
|
237 |
TInt position( 0 );
|
|
238 |
AknLayoutUtils::GetEdwinVerticalPositionAndHeightFromLines(
|
|
239 |
controlSize.iHeight,
|
|
240 |
AknLayoutScalable_Apps::msg_header_pane_t2( 0 ).LayoutLine(),
|
|
241 |
MsgEditorCommons::MsgBaseLineDelta(),
|
|
242 |
iNumberOfLines,
|
|
243 |
position,
|
|
244 |
controlSize.iHeight );
|
|
245 |
}
|
|
246 |
controlSize.iHeight +=iEditortop;
|
|
247 |
if ( controlSize != iSize )
|
|
248 |
{
|
|
249 |
// This may change the height if the content has changed.
|
|
250 |
SetSize( controlSize );
|
|
251 |
}
|
|
252 |
|
|
253 |
aSize = controlSize;
|
|
254 |
}
|
|
255 |
|
|
256 |
// ---------------------------------------------------------
|
|
257 |
// CMsgExpandableControlEditor::CheckEditPermission
|
|
258 |
//
|
|
259 |
// Checks and returns control's edit permissions.
|
|
260 |
// ---------------------------------------------------------
|
|
261 |
//
|
|
262 |
EXPORT_C TUint32 CMsgExpandableControlEditor::CheckEditPermission() const
|
|
263 |
{
|
|
264 |
TUint32 editPermission( CMsgBaseControl::EMsgEditNone );
|
|
265 |
|
|
266 |
if ( CanUndo() )
|
|
267 |
{
|
|
268 |
editPermission |= CMsgBaseControl::EMsgEditUndo;
|
|
269 |
}
|
|
270 |
|
|
271 |
if ( Selection().Length() )
|
|
272 |
{
|
|
273 |
// Selection is on
|
|
274 |
editPermission |= CMsgBaseControl::EMsgEditCopy;
|
|
275 |
if ( !IsReadOnly() )
|
|
276 |
{
|
|
277 |
editPermission |= CMsgBaseControl::EMsgEditCut;
|
|
278 |
}
|
|
279 |
if ( Selection().Length() == TextLength() )
|
|
280 |
{
|
|
281 |
editPermission |= CMsgBaseControl::EMsgEditUnSelectAll;
|
|
282 |
}
|
|
283 |
}
|
|
284 |
|
|
285 |
if ( TextLength() )
|
|
286 |
{
|
|
287 |
editPermission |= CMsgBaseControl::EMsgEditSelectAll;
|
|
288 |
}
|
|
289 |
|
|
290 |
editPermission |= CMsgBaseControl::EMsgEditPaste;
|
|
291 |
|
|
292 |
return editPermission;
|
|
293 |
}
|
|
294 |
|
|
295 |
// ---------------------------------------------------------
|
|
296 |
// CMsgExpandableControlEditor::CursorInFirstLine
|
|
297 |
//
|
|
298 |
// Checks if the cursor is on the first line and return ETrue if it is.
|
|
299 |
// ---------------------------------------------------------
|
|
300 |
//
|
|
301 |
EXPORT_C TBool CMsgExpandableControlEditor::CursorInFirstLine()
|
|
302 |
{
|
|
303 |
TBool cursorOnFirstLine = EFalse;
|
|
304 |
TBool posFormatted = iLayout->PosIsFormatted( 0 );
|
|
305 |
if ( iTextView && posFormatted )
|
|
306 |
{
|
|
307 |
TTmDocPos docPos;
|
|
308 |
iTextView->GetCursorPos( docPos );
|
|
309 |
TTmDocPosSpec docPosSpec( docPos );
|
|
310 |
TTmPosInfo2 posInfo;
|
|
311 |
TTmLineInfo lineInfo;
|
|
312 |
if ( iLayout->FindDocPos( docPosSpec, posInfo, &lineInfo ) )
|
|
313 |
{
|
|
314 |
cursorOnFirstLine = ( lineInfo.iLineNumber == 0 );
|
|
315 |
}
|
|
316 |
}
|
|
317 |
return cursorOnFirstLine;
|
|
318 |
}
|
|
319 |
|
|
320 |
// ---------------------------------------------------------
|
|
321 |
// CMsgExpandableControlEditor::CursorInLastLine
|
|
322 |
//
|
|
323 |
// Checks if the cursor is on the last line and return ETrue if it is.
|
|
324 |
// ---------------------------------------------------------
|
|
325 |
//
|
|
326 |
EXPORT_C TBool CMsgExpandableControlEditor::CursorInLastLine()
|
|
327 |
{
|
|
328 |
TBool cursorOnLastLine = EFalse;
|
|
329 |
TBool posFormatted = iLayout->PosIsFormatted( TextLength() );
|
|
330 |
|
|
331 |
if ( iTextView && posFormatted )
|
|
332 |
{
|
|
333 |
TInt numOfLines = iLayout->NumFormattedLines();
|
|
334 |
if ( numOfLines )
|
|
335 |
{
|
|
336 |
TTmDocPos docPos;
|
|
337 |
iTextView->GetCursorPos( docPos );
|
|
338 |
TTmDocPosSpec docPosSpec( docPos );
|
|
339 |
TTmPosInfo2 posInfo;
|
|
340 |
TTmLineInfo lineInfo;
|
|
341 |
if ( iLayout->FindDocPos( docPosSpec, posInfo, &lineInfo ) )
|
|
342 |
{
|
|
343 |
cursorOnLastLine = ( lineInfo.iLineNumber == numOfLines - 1 );
|
|
344 |
}
|
|
345 |
}
|
|
346 |
else
|
|
347 |
{
|
|
348 |
// Editor is empty.
|
|
349 |
cursorOnLastLine = ETrue;
|
|
350 |
}
|
|
351 |
}
|
|
352 |
|
|
353 |
return cursorOnLastLine;
|
|
354 |
}
|
|
355 |
|
|
356 |
// ---------------------------------------------------------
|
|
357 |
// CMsgExpandableControlEditor::IsFirstLineVisible
|
|
358 |
//
|
|
359 |
// Checks if first text line is visible.
|
|
360 |
// ---------------------------------------------------------
|
|
361 |
//
|
|
362 |
EXPORT_C TBool CMsgExpandableControlEditor::IsFirstLineVisible()
|
|
363 |
{
|
|
364 |
if( TextLayout() )
|
|
365 |
{
|
|
366 |
TPoint dummy;
|
|
367 |
if( TextLayout()->PosInBand( 0, dummy ) )
|
|
368 |
{
|
|
369 |
if( iTextView )
|
|
370 |
{
|
|
371 |
TTmDocPos docPos( 0, ETrue );
|
|
372 |
TTmDocPosSpec docPosSpec( docPos );
|
|
373 |
TTmPosInfo2 posInfo;
|
|
374 |
TTmLineInfo lineInfo;
|
|
375 |
|
|
376 |
if ( iLayout->FindDocPos( docPosSpec, posInfo, &lineInfo ) )
|
|
377 |
{
|
|
378 |
// posInfo.iEdge specifies coordinate position of
|
|
379 |
// intersection of the character edge with the baseline.
|
|
380 |
TInt fontTop = posInfo.iEdge.iY - TextFont()->AscentInPixels();
|
|
381 |
return ( fontTop >= 0 && fontTop <= MsgEditorCommons::EditorViewHeigth() );
|
|
382 |
}
|
|
383 |
}
|
|
384 |
else
|
|
385 |
{
|
|
386 |
return ETrue;
|
|
387 |
}
|
|
388 |
}
|
|
389 |
return EFalse;
|
|
390 |
}
|
|
391 |
|
|
392 |
return ETrue;
|
|
393 |
}
|
|
394 |
|
|
395 |
// ---------------------------------------------------------
|
|
396 |
// CMsgExpandableControlEditor::IsLastLineVisible
|
|
397 |
//
|
|
398 |
// Checks if last text line is visible.
|
|
399 |
// ---------------------------------------------------------
|
|
400 |
//
|
|
401 |
EXPORT_C TBool CMsgExpandableControlEditor::IsLastLineVisible()
|
|
402 |
{
|
|
403 |
if( TextLayout() )
|
|
404 |
{
|
|
405 |
TPoint dummy;
|
|
406 |
if( TextLayout()->PosInBand( TextLength(),dummy ) )
|
|
407 |
{
|
|
408 |
if ( iTextView )
|
|
409 |
{
|
|
410 |
TTmDocPos docPos( TextLength(), EFalse );
|
|
411 |
TTmDocPosSpec docPosSpec( docPos );
|
|
412 |
TTmPosInfo2 posInfo;
|
|
413 |
TTmLineInfo lineInfo;
|
|
414 |
|
|
415 |
if ( iLayout->FindDocPos( docPosSpec, posInfo, &lineInfo ) )
|
|
416 |
{
|
|
417 |
return ( posInfo.iEdge.iY >= 0 &&
|
|
418 |
posInfo.iEdge.iY <= MsgEditorCommons::EditorViewHeigth() );
|
|
419 |
}
|
|
420 |
}
|
|
421 |
else
|
|
422 |
{
|
|
423 |
return ETrue;
|
|
424 |
}
|
|
425 |
}
|
|
426 |
return EFalse;
|
|
427 |
}
|
|
428 |
|
|
429 |
return ETrue;
|
|
430 |
}
|
|
431 |
|
|
432 |
// ---------------------------------------------------------
|
|
433 |
// CMsgExpandableControlEditor::CurrentLineRect
|
|
434 |
//
|
|
435 |
// Returns the current control rect.
|
|
436 |
// ---------------------------------------------------------
|
|
437 |
//
|
|
438 |
EXPORT_C TRect CMsgExpandableControlEditor::CurrentLineRectL()
|
|
439 |
{
|
|
440 |
if ( !iTextView )
|
|
441 |
{
|
|
442 |
User::Leave( KErrGeneral );
|
|
443 |
}
|
|
444 |
|
|
445 |
TTmDocPos docPos;
|
|
446 |
iTextView->GetCursorPos( docPos );
|
|
447 |
iTextView->FinishBackgroundFormattingL();
|
|
448 |
|
|
449 |
TInt cursorPos = Min( docPos.iPos, TextLength() );
|
|
450 |
|
|
451 |
if ( !iLayout->PosIsFormatted( cursorPos ) )
|
|
452 |
{
|
|
453 |
iTextView->SetDocPosL( cursorPos, Selection().Length() ); // after this cursorPos should be formatted
|
|
454 |
ForceScrollBarUpdateL();
|
|
455 |
}
|
|
456 |
|
|
457 |
TRect cursorPosRect;
|
|
458 |
|
|
459 |
if ( iTextView->IsPictureFrameSelected( cursorPosRect, cursorPos ) )
|
|
460 |
{
|
|
461 |
cursorPosRect.Move( TPoint( 0, -iTextView->ViewRect().iTl.iY ) );
|
|
462 |
}
|
|
463 |
else
|
|
464 |
{
|
|
465 |
TTmDocPosSpec docPosSpec( docPos );
|
|
466 |
TTmPosInfo2 posInfo;
|
|
467 |
TTmLineInfo lineInfo;
|
|
468 |
if ( iLayout->FindDocPos( docPosSpec, posInfo, &lineInfo ) )
|
|
469 |
{
|
|
470 |
cursorPosRect = lineInfo.iInnerRect;
|
|
471 |
}
|
|
472 |
//TODO: else what?! We should never get to else branch...
|
|
473 |
}
|
|
474 |
|
|
475 |
return cursorPosRect;
|
|
476 |
}
|
|
477 |
|
|
478 |
// ---------------------------------------------------------
|
|
479 |
// CMsgExpandableControlEditor::DefaultHeight
|
|
480 |
//
|
|
481 |
// Returns a default one line height of the editor.
|
|
482 |
// ---------------------------------------------------------
|
|
483 |
//
|
|
484 |
EXPORT_C TInt CMsgExpandableControlEditor::DefaultHeight() const
|
|
485 |
{
|
|
486 |
return DefaultHeight( EFalse );
|
|
487 |
}
|
|
488 |
|
|
489 |
// ---------------------------------------------------------
|
|
490 |
// CMsgExpandableControlEditor::ClipboardL
|
|
491 |
//
|
|
492 |
// Handles a clipboard operation.
|
|
493 |
// ---------------------------------------------------------
|
|
494 |
//
|
|
495 |
void CMsgExpandableControlEditor::ClipboardL(
|
|
496 |
CEikEdwin::TClipboardFunc aClipboardFunc )
|
|
497 |
{
|
|
498 |
__ASSERT_DEBUG( iTextView, Panic( EMsgNoTextView ) );
|
|
499 |
|
|
500 |
CEikRichTextEditor::ClipboardL( aClipboardFunc );
|
|
501 |
}
|
|
502 |
|
|
503 |
// ---------------------------------------------------------
|
|
504 |
// CMsgExpandableControlEditor::CcpuCanCut
|
|
505 |
// ---------------------------------------------------------
|
|
506 |
//
|
|
507 |
EXPORT_C TBool CMsgExpandableControlEditor::CcpuCanCut() const
|
|
508 |
{
|
|
509 |
TUint32 editPermission = CheckEditPermission();
|
|
510 |
|
|
511 |
if ( iBaseControlObserver )
|
|
512 |
{
|
|
513 |
TRAP_IGNORE(
|
|
514 |
{
|
|
515 |
if ( iBaseControlObserver->HandleEditObserverEventRequestL( this, EMsgDenyCut ) )
|
|
516 |
{
|
|
517 |
editPermission &= ~CMsgBaseControl::EMsgEditCut;
|
|
518 |
}
|
|
519 |
} );
|
|
520 |
}
|
|
521 |
|
|
522 |
return editPermission & CMsgBaseControl::EMsgEditCut;
|
|
523 |
}
|
|
524 |
|
|
525 |
// ---------------------------------------------------------
|
|
526 |
// CMsgExpandableControlEditor::CcpuCanCopy
|
|
527 |
// ---------------------------------------------------------
|
|
528 |
//
|
|
529 |
EXPORT_C TBool CMsgExpandableControlEditor::CcpuCanCopy() const
|
|
530 |
{
|
|
531 |
TUint32 editPermission = CheckEditPermission();
|
|
532 |
|
|
533 |
if (iBaseControlObserver)
|
|
534 |
{
|
|
535 |
TRAP_IGNORE(
|
|
536 |
{
|
|
537 |
if ( iBaseControlObserver->HandleEditObserverEventRequestL( this, EMsgDenyCopy ) )
|
|
538 |
{
|
|
539 |
editPermission &= ~CMsgBaseControl::EMsgEditCopy;
|
|
540 |
}
|
|
541 |
} );
|
|
542 |
}
|
|
543 |
|
|
544 |
return editPermission & CMsgBaseControl::EMsgEditCopy;
|
|
545 |
}
|
|
546 |
|
|
547 |
// ---------------------------------------------------------
|
|
548 |
// CMsgExpandableControlEditor::CcpuCanPaste
|
|
549 |
// ---------------------------------------------------------
|
|
550 |
//
|
|
551 |
EXPORT_C TBool CMsgExpandableControlEditor::CcpuCanPaste() const
|
|
552 |
{
|
|
553 |
TUint32 editPermission = CheckEditPermission();
|
|
554 |
|
|
555 |
if ( !CEikEdwin::CcpuCanPaste() )
|
|
556 |
{
|
|
557 |
editPermission &= ~CMsgBaseControl::EMsgEditPaste;
|
|
558 |
}
|
|
559 |
|
|
560 |
if ( iBaseControlObserver )
|
|
561 |
{
|
|
562 |
TRAP_IGNORE(
|
|
563 |
{
|
|
564 |
if ( iBaseControlObserver->HandleEditObserverEventRequestL( this, EMsgDenyPaste ) )
|
|
565 |
{
|
|
566 |
editPermission &= ~CMsgBaseControl::EMsgEditPaste;
|
|
567 |
}
|
|
568 |
} );
|
|
569 |
}
|
|
570 |
|
|
571 |
return editPermission & CMsgBaseControl::EMsgEditPaste;
|
|
572 |
}
|
|
573 |
|
|
574 |
// ---------------------------------------------------------
|
|
575 |
// CMsgExpandableControlEditor::CcpuCanUndo
|
|
576 |
// ---------------------------------------------------------
|
|
577 |
//
|
|
578 |
EXPORT_C TBool CMsgExpandableControlEditor::CcpuCanUndo() const
|
|
579 |
{
|
|
580 |
return CheckEditPermission() & CMsgBaseControl::EMsgEditUndo;
|
|
581 |
}
|
|
582 |
|
|
583 |
// ---------------------------------------------------------
|
|
584 |
// CMsgExpandableControlEditor::CcpuCutL
|
|
585 |
// ---------------------------------------------------------
|
|
586 |
//
|
|
587 |
EXPORT_C void CMsgExpandableControlEditor::CcpuCutL()
|
|
588 |
{
|
|
589 |
CEikRichTextEditor::ClipboardL( ECut );
|
|
590 |
}
|
|
591 |
|
|
592 |
// ---------------------------------------------------------
|
|
593 |
// CMsgExpandableControlEditor::CcpuCopyL
|
|
594 |
// ---------------------------------------------------------
|
|
595 |
//
|
|
596 |
EXPORT_C void CMsgExpandableControlEditor::CcpuCopyL()
|
|
597 |
{
|
|
598 |
CEikRichTextEditor::ClipboardL( ECopy );
|
|
599 |
}
|
|
600 |
|
|
601 |
// ---------------------------------------------------------
|
|
602 |
// CMsgExpandableControlEditor::CcpuPasteL
|
|
603 |
// ---------------------------------------------------------
|
|
604 |
//
|
|
605 |
EXPORT_C void CMsgExpandableControlEditor::CcpuPasteL()
|
|
606 |
{
|
|
607 |
CEikRichTextEditor::ClipboardL( EPaste );
|
|
608 |
}
|
|
609 |
|
|
610 |
// ---------------------------------------------------------
|
|
611 |
// CMsgExpandableControlEditor::CcpuUndoL
|
|
612 |
// ---------------------------------------------------------
|
|
613 |
//
|
|
614 |
EXPORT_C void CMsgExpandableControlEditor::CcpuUndoL()
|
|
615 |
{
|
|
616 |
UndoL();
|
|
617 |
}
|
|
618 |
|
|
619 |
// ---------------------------------------------------------
|
|
620 |
// CMsgExpandableControlEditor::SetMaxNumberOfChars
|
|
621 |
//
|
|
622 |
// Sets maximun number of characters.
|
|
623 |
// ---------------------------------------------------------
|
|
624 |
//
|
|
625 |
void CMsgExpandableControlEditor::SetMaxNumberOfChars( TInt aMaxNumberOfChars )
|
|
626 |
{
|
|
627 |
iMaxNumberOfChars = aMaxNumberOfChars;
|
|
628 |
if ( Text() )
|
|
629 |
{
|
|
630 |
SetTextLimit( iMaxNumberOfChars );
|
|
631 |
}
|
|
632 |
}
|
|
633 |
|
|
634 |
// ---------------------------------------------------------
|
|
635 |
// CMsgExpandableControlEditor::SetTextContentL
|
|
636 |
//
|
|
637 |
// Sets aText content for the editor.
|
|
638 |
// ---------------------------------------------------------
|
|
639 |
//
|
|
640 |
EXPORT_C void CMsgExpandableControlEditor::SetTextContentL( CRichText& aText )
|
|
641 |
{
|
|
642 |
MEBLOGGER_ENTERFN("CMsgExpandableControlEditor::SetTextContentL");
|
|
643 |
|
|
644 |
MEBLOGGER_WRITE("#1");
|
|
645 |
MEBLOGGER_WRITE_TIMESTAMP("");
|
|
646 |
|
|
647 |
if ( IsPlainTextMode() )
|
|
648 |
{
|
|
649 |
CRichText* richText = RichText();
|
|
650 |
|
|
651 |
MEBLOGGER_WRITEF( _L( "MEB: SetTextContentL: Copying text, length %d" ), aText.DocumentLength() );
|
|
652 |
|
|
653 |
// Ignore the original formatting on plain text mode and set the
|
|
654 |
// new rich text object to use current formatting parameters.
|
|
655 |
aText.SetGlobalParaFormat( richText->GlobalParaFormatLayer() );
|
|
656 |
aText.SetGlobalCharFormat( richText->GlobalCharFormatLayer() );
|
|
657 |
|
|
658 |
CEikEdwin::CopyDocumentContentL( aText, *richText );
|
|
659 |
TInt documentLength = richText->DocumentLength();
|
|
660 |
|
|
661 |
MEBLOGGER_WRITEF( _L( "MEB: SetTextContentL: Copied text, length %d" ), documentLength );
|
|
662 |
|
|
663 |
if ( iMaxNumberOfChars &&
|
|
664 |
documentLength > iMaxNumberOfChars )
|
|
665 |
{
|
|
666 |
richText->DeleteL( iMaxNumberOfChars, documentLength - iMaxNumberOfChars );
|
|
667 |
documentLength = richText->DocumentLength();
|
|
668 |
}
|
|
669 |
|
|
670 |
const TChar LF( 0x0A );
|
|
671 |
const TChar CR( 0x0D );
|
|
672 |
|
|
673 |
TInt i = 0;
|
|
674 |
while ( i < documentLength )
|
|
675 |
{
|
|
676 |
TPtrC ptr = richText->Read( i, 1 );
|
|
677 |
TInt remove = 0;
|
|
678 |
TBool addParDeli = EFalse;
|
|
679 |
if ( ptr.Locate( CEditableText::EPictureCharacter ) != KErrNotFound )
|
|
680 |
{
|
|
681 |
remove++;
|
|
682 |
}
|
|
683 |
else if ( ptr.Locate( CR ) != KErrNotFound )
|
|
684 |
{
|
|
685 |
// "CR"
|
|
686 |
remove++;
|
|
687 |
addParDeli = ETrue;
|
|
688 |
if ( i < documentLength - 1 &&
|
|
689 |
aText.Read( i + 1, 1 ).Locate( LF ) != KErrNotFound )
|
|
690 |
{
|
|
691 |
// "CR+LF"
|
|
692 |
remove++;
|
|
693 |
}
|
|
694 |
}
|
|
695 |
else if ( ptr.Locate( LF ) != KErrNotFound )
|
|
696 |
{
|
|
697 |
// "LF"
|
|
698 |
remove++;
|
|
699 |
addParDeli = ETrue;
|
|
700 |
}
|
|
701 |
|
|
702 |
if ( remove )
|
|
703 |
{
|
|
704 |
MEBLOGGER_WRITEF( _L( "MEB: SetTextContentL: removing %d characters" ), remove );
|
|
705 |
richText->DeleteL( i, remove );
|
|
706 |
MEBLOGGER_WRITEF( _L( "MEB: SetTextContentL: removed %d characters" ), remove );
|
|
707 |
documentLength -= remove;
|
|
708 |
if ( addParDeli )
|
|
709 |
{
|
|
710 |
MEBLOGGER_WRITEF( _L( "MEB: SetTextContentL: Inserting paragraph delimeter" ) );
|
|
711 |
richText->InsertL( i, CEditableText::EParagraphDelimiter );
|
|
712 |
MEBLOGGER_WRITEF( _L( "MEB: SetTextContentL: Inserted paragraph delimeter" ) );
|
|
713 |
documentLength++;
|
|
714 |
i++;
|
|
715 |
}
|
|
716 |
}
|
|
717 |
else
|
|
718 |
{
|
|
719 |
i++;
|
|
720 |
}
|
|
721 |
}
|
|
722 |
}
|
|
723 |
else
|
|
724 |
{
|
|
725 |
CopyDocumentContentL( aText, *GlobalText() );
|
|
726 |
}
|
|
727 |
|
|
728 |
SetAmountToFormatL( ETrue );
|
|
729 |
|
|
730 |
MEBLOGGER_WRITE("#2");
|
|
731 |
MEBLOGGER_WRITE_TIMESTAMP("");
|
|
732 |
|
|
733 |
MEBLOGGER_LEAVEFN("CMsgExpandableControlEditor::SetTextContentL");
|
|
734 |
}
|
|
735 |
|
|
736 |
// ---------------------------------------------------------
|
|
737 |
// CMsgExpandableControlEditor::MinimumDefaultHeight
|
|
738 |
//
|
|
739 |
// Returns a minimum one line height of the editor.
|
|
740 |
// ---------------------------------------------------------
|
|
741 |
//
|
|
742 |
TInt CMsgExpandableControlEditor::MinimumDefaultHeight() const
|
|
743 |
{
|
|
744 |
return DefaultHeight( ETrue );
|
|
745 |
}
|
|
746 |
|
|
747 |
// ---------------------------------------------------------
|
|
748 |
// CMsgExpandableControlEditor::Reset
|
|
749 |
//
|
|
750 |
// Clear contents.
|
|
751 |
// ---------------------------------------------------------
|
|
752 |
//
|
|
753 |
EXPORT_C void CMsgExpandableControlEditor::Reset()
|
|
754 |
{
|
|
755 |
if ( iTextView )
|
|
756 |
{
|
|
757 |
TInt documentLength = RichText()->DocumentLength();
|
|
758 |
|
|
759 |
RichText()->Reset();
|
|
760 |
|
|
761 |
iTextView->SetPendingSelection( TCursorSelection( 0, 0 ) );
|
|
762 |
TRAP_IGNORE( iTextView->HandleInsertDeleteL( TCursorSelection( 0, 0 ),
|
|
763 |
documentLength ) );
|
|
764 |
}
|
|
765 |
else
|
|
766 |
{
|
|
767 |
RichText()->Reset();
|
|
768 |
}
|
|
769 |
}
|
|
770 |
|
|
771 |
// ---------------------------------------------------------
|
|
772 |
// CMsgExpandableControlEditor::SetBaseControlObserver
|
|
773 |
//
|
|
774 |
// Sets base control observer.
|
|
775 |
// ---------------------------------------------------------
|
|
776 |
//
|
|
777 |
EXPORT_C void CMsgExpandableControlEditor::SetBaseControlObserver(
|
|
778 |
MMsgBaseControlObserver& aBaseControlObserver )
|
|
779 |
{
|
|
780 |
iBaseControlObserver = &aBaseControlObserver;
|
|
781 |
}
|
|
782 |
|
|
783 |
// ---------------------------------------------------------
|
|
784 |
// CMsgExpandableControlEditor::OfferKeyEventL
|
|
785 |
//
|
|
786 |
// Handles key event.
|
|
787 |
// ---------------------------------------------------------
|
|
788 |
//
|
|
789 |
EXPORT_C TKeyResponse CMsgExpandableControlEditor::OfferKeyEventL(
|
|
790 |
const TKeyEvent& aKeyEvent, TEventCode aType)
|
|
791 |
{
|
|
792 |
if ( IsReadOnly() )
|
|
793 |
{
|
|
794 |
TCursorPosition::TMovementType movetype;
|
|
795 |
|
|
796 |
switch ( aKeyEvent.iCode )
|
|
797 |
{
|
|
798 |
case EKeyUpArrow:
|
|
799 |
movetype = TCursorPosition::EFPageUp;
|
|
800 |
break;
|
|
801 |
|
|
802 |
case EKeyDownArrow:
|
|
803 |
movetype = TCursorPosition::EFPageDown;
|
|
804 |
break;
|
|
805 |
|
|
806 |
default:
|
|
807 |
return CEikRichTextEditor::OfferKeyEventL( aKeyEvent, aType );
|
|
808 |
}
|
|
809 |
|
|
810 |
iTextView->MoveCursorL( movetype, EFalse );
|
|
811 |
|
|
812 |
return EKeyWasConsumed;
|
|
813 |
}
|
|
814 |
else
|
|
815 |
{
|
|
816 |
return CEikRichTextEditor::OfferKeyEventL( aKeyEvent, aType );
|
|
817 |
}
|
|
818 |
}
|
|
819 |
|
|
820 |
// ---------------------------------------------------------
|
|
821 |
// CMsgExpandableControlEditor::HandleResourceChange
|
|
822 |
//
|
|
823 |
// Sets correct highlight extension.
|
|
824 |
// ---------------------------------------------------------
|
|
825 |
//
|
|
826 |
void CMsgExpandableControlEditor::HandleResourceChange( TInt aType )
|
|
827 |
{
|
|
828 |
if ( aType == KEikDynamicLayoutVariantSwitch )
|
|
829 |
{
|
|
830 |
ResolveLayouts();
|
|
831 |
LayoutEdwin();
|
|
832 |
|
|
833 |
TRAP_IGNORE(
|
|
834 |
{
|
|
835 |
if ( iTextView )
|
|
836 |
{
|
|
837 |
TCursorSelection currentSelection = iTextView->Selection() ;
|
|
838 |
|
|
839 |
if ( currentSelection.Length() > 0 )
|
|
840 |
{
|
|
841 |
iTextView->SetSelectionL( currentSelection );
|
|
842 |
}
|
|
843 |
else
|
|
844 |
{
|
|
845 |
iTextView->SetDocPosL( currentSelection.iCursorPos, EFalse );
|
|
846 |
}
|
|
847 |
}
|
|
848 |
} );
|
|
849 |
}
|
|
850 |
|
|
851 |
CEikRichTextEditor::HandleResourceChange( aType );
|
|
852 |
}
|
|
853 |
|
|
854 |
// ---------------------------------------------------------
|
|
855 |
// CMsgExpandableControlEditor::IsPlainTextMode
|
|
856 |
//
|
|
857 |
// Checks if the plain text mode is on and returns ETrue if it is.
|
|
858 |
// ---------------------------------------------------------
|
|
859 |
//
|
|
860 |
TBool CMsgExpandableControlEditor::IsPlainTextMode() const
|
|
861 |
{
|
|
862 |
return iFlags & EMsgControlModePlainTextMode;
|
|
863 |
}
|
|
864 |
|
|
865 |
// ---------------------------------------------------------
|
|
866 |
// CMsgExpandableControlEditor::LayoutEdwin
|
|
867 |
// ---------------------------------------------------------
|
|
868 |
//
|
|
869 |
void CMsgExpandableControlEditor::LayoutEdwin()
|
|
870 |
{
|
|
871 |
TAknLayoutRect msgTextPane;
|
|
872 |
msgTextPane.LayoutRect( MsgEditorCommons::MsgDataPane(),
|
|
873 |
AknLayoutScalable_Apps::msg_text_pane( 0 ).LayoutLine() );
|
|
874 |
|
|
875 |
TAknLayoutRect msgHeaderPane;
|
|
876 |
msgHeaderPane.LayoutRect( msgTextPane.Rect(),
|
|
877 |
AknLayoutScalable_Apps::msg_header_pane().LayoutLine() );
|
|
878 |
|
|
879 |
TRect parentRect( msgHeaderPane.Rect() );
|
|
880 |
parentRect.Move( 0, iParentControl->Position().iY );
|
|
881 |
|
|
882 |
DoLayoutEdwin( parentRect,
|
|
883 |
AknLayoutScalable_Apps::msg_header_pane_t2( 0 ).LayoutLine() );
|
|
884 |
}
|
|
885 |
|
|
886 |
// ---------------------------------------------------------
|
|
887 |
// CMsgExpandableControlEditor::DoLayoutEdwin
|
|
888 |
//
|
|
889 |
// Performs the layout setting for edwin according to the given
|
|
890 |
// parameters. Used from LayoutEdwin or some of it's derived versions.
|
|
891 |
// ---------------------------------------------------------
|
|
892 |
//
|
|
893 |
void CMsgExpandableControlEditor::DoLayoutEdwin( const TRect& aEdwinParent,
|
|
894 |
const TAknTextLineLayout& aLayout )
|
|
895 |
{
|
|
896 |
TPoint position( iPosition );
|
|
897 |
|
|
898 |
// Layout edwin as two lines to get the base line delta override activated.
|
|
899 |
TInt lineNumber( 0 );
|
|
900 |
AknLayoutUtils::LayoutEdwin( this,
|
|
901 |
aEdwinParent,
|
|
902 |
aLayout,
|
|
903 |
2,
|
|
904 |
MsgEditorCommons::MsgBaseLineDelta(),
|
|
905 |
EAknsCIQsnTextColorsCG6,
|
|
906 |
lineNumber );
|
|
907 |
|
|
908 |
// Resize the edwin to the correct size. Also set the original position.
|
|
909 |
TInt notUsed( 0 );
|
|
910 |
TInt height( 0 );
|
|
911 |
AknLayoutUtils::GetEdwinVerticalPositionAndHeightFromLines(
|
|
912 |
aEdwinParent.Size().iHeight,
|
|
913 |
aLayout,
|
|
914 |
MsgEditorCommons::MsgBaseLineDelta(),
|
|
915 |
iNumberOfLines,
|
|
916 |
notUsed,
|
|
917 |
height );
|
|
918 |
|
|
919 |
TRect editorRect( position, TSize( iSize.iWidth, height ) );
|
|
920 |
SetRect( editorRect );
|
|
921 |
}
|
|
922 |
|
|
923 |
// ---------------------------------------------------------
|
|
924 |
// CMsgExpandableControlEditor::AdjustLineHeightL
|
|
925 |
// ---------------------------------------------------------
|
|
926 |
//
|
|
927 |
EXPORT_C void CMsgExpandableControlEditor::AdjustLineHeightL()
|
|
928 |
{
|
|
929 |
// nop
|
|
930 |
}
|
|
931 |
|
|
932 |
// ---------------------------------------------------------
|
|
933 |
// CMsgExpandableControlEditor::TextFont
|
|
934 |
// ---------------------------------------------------------
|
|
935 |
//
|
|
936 |
EXPORT_C const CFont* CMsgExpandableControlEditor::TextFont() const
|
|
937 |
{
|
|
938 |
return iTextLayout.Font();
|
|
939 |
}
|
|
940 |
|
|
941 |
// ---------------------------------------------------------
|
|
942 |
// CMsgExpandableControlEditor::DefaultHeight
|
|
943 |
// ---------------------------------------------------------
|
|
944 |
//
|
|
945 |
TInt CMsgExpandableControlEditor::DefaultHeight( TBool /*aOneToOne*/ ) const
|
|
946 |
{
|
|
947 |
return TextFont()->HeightInPixels();
|
|
948 |
}
|
|
949 |
|
|
950 |
// ---------------------------------------------------------
|
|
951 |
// CMsgExpandableControlEditor::VirtualHeight
|
|
952 |
//
|
|
953 |
// Returns approximate height of text. In band formatting mode
|
|
954 |
// we have to calculate the average chars per line and
|
|
955 |
// average line in view values by ourself as we might get called
|
|
956 |
// in a callback when edwin does not contain up-to-date values.
|
|
957 |
// ---------------------------------------------------------
|
|
958 |
//
|
|
959 |
EXPORT_C TInt CMsgExpandableControlEditor::VirtualHeight()
|
|
960 |
{
|
|
961 |
TInt heightInPixels( 0 );
|
|
962 |
TInt msgBaseLineDelta( MsgEditorCommons::MsgBaseLineDelta() );
|
|
963 |
|
|
964 |
if ( iLayout->IsFormattingBand() )
|
|
965 |
{
|
|
966 |
TInt docLength = iLayout->DocumentLength();
|
|
967 |
|
|
968 |
TInt avgCharsPerLine = iLayout->FormattedLength() / iLayout->NumFormattedLines();
|
|
969 |
TInt avgLinesInViewRect= Max( 1, iTextView->ViewRect().Height() *
|
|
970 |
iLayout->NumFormattedLines() /
|
|
971 |
iLayout->FormattedHeightInPixels() );
|
|
972 |
|
|
973 |
const TInt approxTotalLines = Max( docLength / avgCharsPerLine,
|
|
974 |
iText->ParagraphCount() );
|
|
975 |
const TInt approxLineHeight = iTextView->ViewRect().Height() / avgLinesInViewRect;
|
|
976 |
heightInPixels = approxTotalLines * approxLineHeight;
|
|
977 |
}
|
|
978 |
else
|
|
979 |
{
|
|
980 |
if ( iTextView )
|
|
981 |
{
|
|
982 |
// Force formatting to complete so that
|
|
983 |
// correct height can be retrieved.
|
|
984 |
TRAP_IGNORE( iTextView->FinishBackgroundFormattingL() );
|
|
985 |
}
|
|
986 |
|
|
987 |
heightInPixels = iLayout->FormattedHeightInPixels();
|
|
988 |
}
|
|
989 |
|
|
990 |
heightInPixels = Max( heightInPixels, iLayout->FormattedHeightInPixels() );
|
|
991 |
MsgEditorCommons::RoundToPreviousLine( heightInPixels, msgBaseLineDelta );
|
|
992 |
|
|
993 |
return heightInPixels;
|
|
994 |
}
|
|
995 |
|
|
996 |
// ---------------------------------------------------------
|
|
997 |
// CMsgExpandableControlEditor::VirtualVisibleTop
|
|
998 |
//
|
|
999 |
// Returns a topmost visible text position. In band formatting mode
|
|
1000 |
// we have to calculate the average chars per line value
|
|
1001 |
// by ourself as we might get called in a callback when edwin
|
|
1002 |
// does not contain up-to-date value.
|
|
1003 |
// ---------------------------------------------------------
|
|
1004 |
//
|
|
1005 |
EXPORT_C TInt CMsgExpandableControlEditor::VirtualVisibleTop()
|
|
1006 |
{
|
|
1007 |
TInt ret( 0 );
|
|
1008 |
|
|
1009 |
TInt msgBaseLineDelta( MsgEditorCommons::MsgBaseLineDelta() );
|
|
1010 |
|
|
1011 |
if ( iLayout->IsFormattingBand() )
|
|
1012 |
{
|
|
1013 |
TInt avgCharsPerLine = iLayout->FormattedLength() / iLayout->NumFormattedLines();
|
|
1014 |
|
|
1015 |
TInt topLeftDocPos = iLayout->FirstDocPosFullyInBand();
|
|
1016 |
TInt approxTopVisibleLine = topLeftDocPos / avgCharsPerLine;
|
|
1017 |
|
|
1018 |
if ( approxTopVisibleLine == 0 &&
|
|
1019 |
topLeftDocPos > 0 )
|
|
1020 |
{
|
|
1021 |
ret = iLayout->PixelsAboveBand();
|
|
1022 |
}
|
|
1023 |
else
|
|
1024 |
{
|
|
1025 |
TInt avgLinesInViewRect= Max( 1, iTextView->ViewRect().Height() *
|
|
1026 |
iLayout->NumFormattedLines() /
|
|
1027 |
iLayout->FormattedHeightInPixels() );
|
|
1028 |
|
|
1029 |
TInt approxLineHeight = iTextView->ViewRect().Height() / avgLinesInViewRect;
|
|
1030 |
ret = approxTopVisibleLine * approxLineHeight;
|
|
1031 |
}
|
|
1032 |
}
|
|
1033 |
else
|
|
1034 |
{
|
|
1035 |
// Round to the last full line height. Division removes the fraction since
|
|
1036 |
// result is integer (i.e. non floating point value).
|
|
1037 |
ret = iLayout->PixelsAboveBand();
|
|
1038 |
}
|
|
1039 |
|
|
1040 |
ret = Max( ret, iLayout->PixelsAboveBand() );
|
|
1041 |
MsgEditorCommons::RoundToPreviousLine( ret, msgBaseLineDelta );
|
|
1042 |
|
|
1043 |
return ret;
|
|
1044 |
}
|
|
1045 |
|
|
1046 |
// ---------------------------------------------------------
|
|
1047 |
// CMsgExpandableControlEditor::ActivateL
|
|
1048 |
// ---------------------------------------------------------
|
|
1049 |
//
|
|
1050 |
EXPORT_C void CMsgExpandableControlEditor::ActivateL()
|
|
1051 |
{
|
|
1052 |
if ( IsActivated() )
|
|
1053 |
{
|
|
1054 |
return;
|
|
1055 |
}
|
|
1056 |
|
|
1057 |
TInt cursorPos = 0;
|
|
1058 |
|
|
1059 |
if ( iTextView )
|
|
1060 |
{
|
|
1061 |
cursorPos = CursorPos();
|
|
1062 |
}
|
|
1063 |
|
|
1064 |
LayoutEdwin();
|
|
1065 |
SetTextSkinColorIdL();
|
|
1066 |
|
|
1067 |
CEikRichTextEditor::ActivateL();
|
|
1068 |
|
|
1069 |
iTextView->SetDocPosL( cursorPos );
|
|
1070 |
if ( !iCustomDraw )
|
|
1071 |
{
|
|
1072 |
// Swap the custom drawer to our own to show text lines.
|
|
1073 |
const MFormCustomDraw* customDraw = TextLayout()->CustomDraw();
|
|
1074 |
|
|
1075 |
iCustomDraw = CMsgEditorCustomDraw::NewL( customDraw, this, iControlType);
|
|
1076 |
|
|
1077 |
TextLayout()->SetCustomDraw( iCustomDraw );
|
|
1078 |
}
|
|
1079 |
}
|
|
1080 |
|
|
1081 |
// ---------------------------------------------------------
|
|
1082 |
// CMsgExpandableControlEditor::ItemFinder
|
|
1083 |
// ---------------------------------------------------------
|
|
1084 |
//
|
|
1085 |
EXPORT_C CItemFinder* CMsgExpandableControlEditor::ItemFinder() const
|
|
1086 |
{
|
|
1087 |
return iItemFinder;
|
|
1088 |
}
|
|
1089 |
|
|
1090 |
// ---------------------------------------------------------
|
|
1091 |
// CMsgExpandableControlEditor::FocusChanged
|
|
1092 |
// ---------------------------------------------------------
|
|
1093 |
//
|
|
1094 |
EXPORT_C void CMsgExpandableControlEditor::FocusChanged( TDrawNow aDrawNow )
|
|
1095 |
{
|
|
1096 |
CEikEdwin::FocusChanged( aDrawNow );
|
|
1097 |
|
|
1098 |
TRAP_IGNORE( DoFocusChangedL() );
|
|
1099 |
}
|
|
1100 |
|
|
1101 |
// ---------------------------------------------------------
|
|
1102 |
// CMsgExpandableControlEditor::DoFocusChangedL
|
|
1103 |
// ---------------------------------------------------------
|
|
1104 |
//
|
|
1105 |
void CMsgExpandableControlEditor::DoFocusChangedL()
|
|
1106 |
{
|
|
1107 |
SetTextSkinColorIdL();
|
|
1108 |
|
|
1109 |
if( ! ( iFlags & EMsgControlModeDoNotDrawFrameBgContext ) &&
|
|
1110 |
! static_cast<const CMsgBaseControl*>( iParentControl )->IsReadOnly() )
|
|
1111 |
{
|
|
1112 |
if( IsFocused( ) )
|
|
1113 |
{
|
|
1114 |
// The focus arrives so lets so the frame
|
|
1115 |
// It is drawn between the outer and inner rects
|
|
1116 |
TRect outer, inner;
|
|
1117 |
OuterAndInnerRects( outer, inner );
|
|
1118 |
|
|
1119 |
if( !iFrameBgContext )
|
|
1120 |
{
|
|
1121 |
iFrameBgContext =
|
|
1122 |
CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrInput,
|
|
1123 |
outer,
|
|
1124 |
inner,
|
|
1125 |
EFalse );
|
|
1126 |
iFrameBgContext->SetParentContext( iBgContext );
|
|
1127 |
}
|
|
1128 |
else
|
|
1129 |
{
|
|
1130 |
iFrameBgContext->SetFrameRects( outer, inner );
|
|
1131 |
}
|
|
1132 |
SetSkinBackgroundControlContextL( iFrameBgContext );
|
|
1133 |
}
|
|
1134 |
else
|
|
1135 |
{ // Focus leaves so lets remove the skin bg control contex
|
|
1136 |
SetSkinBackgroundControlContextL( iBgContext );
|
|
1137 |
}
|
|
1138 |
}
|
|
1139 |
}
|
|
1140 |
|
|
1141 |
// ---------------------------------------------------------
|
|
1142 |
// CMsgExpandableControlEditor::HandleFrameSizeChangeL
|
|
1143 |
// ---------------------------------------------------------
|
|
1144 |
//
|
|
1145 |
void CMsgExpandableControlEditor::HandleFrameSizeChangeL()
|
|
1146 |
{
|
|
1147 |
if( IsFocused( ) )
|
|
1148 |
{
|
|
1149 |
// We have focus so lets resize the frame context
|
|
1150 |
if( ! (iFlags & EMsgControlModeDoNotDrawFrameBgContext ) &&
|
|
1151 |
! static_cast<const CMsgBaseControl*>( iParentControl )->IsReadOnly() )
|
|
1152 |
{
|
|
1153 |
// The size of the frame has changed so lets find out
|
|
1154 |
// the outer and inner rects again
|
|
1155 |
TRect outer, inner;
|
|
1156 |
OuterAndInnerRects( outer, inner );
|
|
1157 |
|
|
1158 |
if( !iFrameBgContext )
|
|
1159 |
{
|
|
1160 |
iFrameBgContext =
|
|
1161 |
CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrInput,
|
|
1162 |
outer,
|
|
1163 |
inner,
|
|
1164 |
EFalse );
|
|
1165 |
iFrameBgContext->SetParentContext( iBgContext );
|
|
1166 |
}
|
|
1167 |
|
|
1168 |
iFrameBgContext->SetFrameRects( outer, inner );
|
|
1169 |
SetSkinBackgroundControlContextL( iFrameBgContext );
|
|
1170 |
}
|
|
1171 |
}
|
|
1172 |
}
|
|
1173 |
|
|
1174 |
// ---------------------------------------------------------
|
|
1175 |
// CMsgExpandableControlEditor::OuterAndInnerRects
|
|
1176 |
// ---------------------------------------------------------
|
|
1177 |
//
|
|
1178 |
void CMsgExpandableControlEditor::OuterAndInnerRects( TRect& aOuter, TRect& aInner )
|
|
1179 |
{
|
|
1180 |
TRect rect( Rect( ) );
|
|
1181 |
TRect focused ( iParentControl->Rect( ) );
|
|
1182 |
|
|
1183 |
// If we are out of screen, start it just from the baseline offset
|
|
1184 |
TInt top = MsgEditorCommons::MsgBaseLineOffset();
|
|
1185 |
if ( focused.iTl.iY < top )
|
|
1186 |
{
|
|
1187 |
focused.iTl.iY = top;
|
|
1188 |
}
|
|
1189 |
TInt maxBodyHeight( MsgEditorCommons::EditorViewHeigth() );
|
|
1190 |
if ( focused.iBr.iY > maxBodyHeight )
|
|
1191 |
{
|
|
1192 |
focused.iBr.iY = maxBodyHeight;
|
|
1193 |
}
|
|
1194 |
|
|
1195 |
aOuter.SetRect( rect.iTl.iX-1,
|
|
1196 |
focused.iTl.iY,
|
|
1197 |
rect.iBr.iX,
|
|
1198 |
focused.iBr.iY );
|
|
1199 |
|
|
1200 |
TAknLayoutRect tl;
|
|
1201 |
TAknLayoutRect br;
|
|
1202 |
tl.LayoutRect( aOuter, AknLayoutScalable_Avkon::input_focus_pane_g2().LayoutLine() );
|
|
1203 |
br.LayoutRect( aOuter, AknLayoutScalable_Avkon::input_focus_pane_g5().LayoutLine() );
|
|
1204 |
|
|
1205 |
aInner.SetRect( aOuter.iTl.iX - 1,
|
|
1206 |
aOuter.iTl.iY + tl.Rect().Height(),
|
|
1207 |
aOuter.iBr.iX,
|
|
1208 |
aOuter.iBr.iY - br.Rect().Height() );
|
|
1209 |
}
|
|
1210 |
|
|
1211 |
|
|
1212 |
// ---------------------------------------------------------
|
|
1213 |
// CMsgExpandableControlEditor::ResolveLayouts
|
|
1214 |
//
|
|
1215 |
//
|
|
1216 |
// ---------------------------------------------------------
|
|
1217 |
//
|
|
1218 |
void CMsgExpandableControlEditor::ResolveLayouts()
|
|
1219 |
{
|
|
1220 |
TAknLayoutRect msgTextPane;
|
|
1221 |
msgTextPane.LayoutRect( MsgEditorCommons::MsgDataPane(),
|
|
1222 |
AknLayoutScalable_Apps::msg_text_pane( 0 ).LayoutLine() );
|
|
1223 |
|
|
1224 |
TAknLayoutRect msgHeaderPane;
|
|
1225 |
msgHeaderPane.LayoutRect( msgTextPane.Rect(),
|
|
1226 |
AknLayoutScalable_Apps::msg_header_pane().LayoutLine() );
|
|
1227 |
|
|
1228 |
iTextLayout.LayoutText( msgHeaderPane.Rect(),
|
|
1229 |
AknLayoutScalable_Apps::msg_header_pane_t2( 0 ).LayoutLine() );
|
|
1230 |
TRect dataPane = MsgEditorCommons::MsgDataPane();
|
|
1231 |
|
|
1232 |
|
|
1233 |
TAknTextLineLayout editorLineLayout;
|
|
1234 |
TAknLayoutText editorLayout;
|
|
1235 |
|
|
1236 |
editorLineLayout = AknLayoutScalable_Apps::msg_header_pane_t2( 0 ).LayoutLine();
|
|
1237 |
|
|
1238 |
editorLayout.LayoutText( msgHeaderPane.Rect(), editorLineLayout );
|
|
1239 |
|
|
1240 |
iEditortop = editorLayout.TextRect().iTl.iY - msgHeaderPane.Rect().iTl.iY;
|
|
1241 |
if ( iCustomDraw )
|
|
1242 |
{
|
|
1243 |
iCustomDraw->ResolveLayouts();
|
|
1244 |
}
|
|
1245 |
}
|
|
1246 |
|
|
1247 |
// ---------------------------------------------------------
|
|
1248 |
// CMsgExpandableControlEditor::PrepareForReadOnlyL
|
|
1249 |
// ---------------------------------------------------------
|
|
1250 |
//
|
|
1251 |
void CMsgExpandableControlEditor::PrepareForReadOnlyL( TBool aReadOnly )
|
|
1252 |
{
|
|
1253 |
if ( IsReadOnly() == aReadOnly )
|
|
1254 |
{
|
|
1255 |
return;
|
|
1256 |
}
|
|
1257 |
|
|
1258 |
SetReadOnly( aReadOnly );
|
|
1259 |
SetTextSkinColorIdL();
|
|
1260 |
|
|
1261 |
if ( aReadOnly )
|
|
1262 |
{
|
|
1263 |
AddFlagToUserFlags( CEikEdwin::EAvkonDisableCursor );
|
|
1264 |
}
|
|
1265 |
else
|
|
1266 |
{
|
|
1267 |
RemoveFlagFromUserFlags( CEikEdwin::EAvkonDisableCursor );
|
|
1268 |
}
|
|
1269 |
|
|
1270 |
}
|
|
1271 |
|
|
1272 |
// ---------------------------------------------------------
|
|
1273 |
// CMsgExpandableControlEditor::SetTextSkinColorIdL
|
|
1274 |
// ---------------------------------------------------------
|
|
1275 |
//
|
|
1276 |
void CMsgExpandableControlEditor::SetTextSkinColorIdL()
|
|
1277 |
{
|
|
1278 |
CEikEdwin::SetTextSkinColorIdL( EAknsCIQsnTextColorsCG6 );
|
|
1279 |
}
|
|
1280 |
|
|
1281 |
// ---------------------------------------------------------
|
|
1282 |
// CMsgExpandableControlEditor::IsCursorVisibleL
|
|
1283 |
// ---------------------------------------------------------
|
|
1284 |
//
|
|
1285 |
TBool CMsgExpandableControlEditor::IsCursorVisibleL()
|
|
1286 |
{
|
|
1287 |
TBool result = EFalse;
|
|
1288 |
if ( iTextView )
|
|
1289 |
{
|
|
1290 |
TPoint cursorPos;
|
|
1291 |
|
|
1292 |
if ( iTextView->DocPosToXyPosL( CursorPos(), cursorPos ) &&
|
|
1293 |
iTextView->ViewRect().Contains( cursorPos ) )
|
|
1294 |
{
|
|
1295 |
result = ETrue;
|
|
1296 |
}
|
|
1297 |
}
|
|
1298 |
return result;
|
|
1299 |
}
|
|
1300 |
// ---------------------------------------------------------
|
|
1301 |
// CMsgExpandableControlEditor::MsgEditorCustomDraw
|
|
1302 |
// ---------------------------------------------------------
|
|
1303 |
//
|
|
1304 |
CMsgEditorCustomDraw* CMsgExpandableControlEditor::MsgEditorCustomDraw() const
|
|
1305 |
{
|
|
1306 |
return iCustomDraw;
|
|
1307 |
}
|
|
1308 |
|
|
1309 |
|
|
1310 |
// ---------------------------------------------------------
|
|
1311 |
// CMsgExpandableControlEditor::SetControlType
|
|
1312 |
// ---------------------------------------------------------
|
|
1313 |
//
|
|
1314 |
void CMsgExpandableControlEditor::SetControlType(TInt actrltype)
|
|
1315 |
{
|
|
1316 |
iControlType = actrltype;
|
|
1317 |
}
|
|
1318 |
// End of File
|