|
1 /* |
|
2 * Copyright (c) 2002-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: Implementation for CFepInputContextFieldJp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <peninputlayout.h> |
|
20 #include <peninputcontextfieldjp.h> |
|
21 #include <peninputlayoutinsertionpoint.h> |
|
22 #include <peninputcmd.h> |
|
23 #include <aknenv.h> |
|
24 #include <peninputeventjp.h> |
|
25 #include <txtetext.h> // CEditableText::EParagraphDelimiter |
|
26 |
|
27 const TInt KGapLeftOfEachLine = 2; |
|
28 const TInt KConversionRectMarginY = 2; |
|
29 const TInt KConversionLeftMarginX = 1; |
|
30 const TInt KConversionRightMarginX = 3; |
|
31 const TInt KConversionSelectingMargin = 1; |
|
32 |
|
33 #ifdef _DEBUG |
|
34 _LIT(KPeninputICFJp, "Peninput ICF JP"); |
|
35 enum TPanicPeninputICFJp |
|
36 { |
|
37 EPanicICFJpStartInlineAlready = 1, |
|
38 EPanicICFJpCursorPositionNotReady, |
|
39 EPanicICFJpCommitInlineNotReady, |
|
40 EPanicICFJpUpdateInlineNotReady, |
|
41 EPanicICFJpDoUpdateInlineNotReady, |
|
42 EPanicICFJpEnd |
|
43 }; |
|
44 #endif // _DEBUG |
|
45 |
|
46 // ======== LOCAL FUNCTIONS ======== |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // Check that target is between TCursorSelection. |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 TInt PositionInArea( const TInt aTargetVal, const TCursorSelection aArea ) |
|
53 { |
|
54 return Max ( Min( aTargetVal, aArea.HigherPos() ), aArea.LowerPos() ); |
|
55 } |
|
56 |
|
57 // ======== MEMBER FUNCTIONS ======== |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Two-phased constructor. |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 EXPORT_C CFepInputContextFieldJp* CFepInputContextFieldJp::NewL( TRect aRect, |
|
64 CFepUiLayout* aUiLayout,TInt aControlId ) |
|
65 { |
|
66 CFepInputContextFieldJp* self = |
|
67 new (ELeave) CFepInputContextFieldJp( aRect, aUiLayout,aControlId ); |
|
68 |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(); |
|
71 CleanupStack::Pop(self); |
|
72 |
|
73 return self; |
|
74 } |
|
75 |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // Destructor |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C CFepInputContextFieldJp::~CFepInputContextFieldJp() |
|
82 { |
|
83 delete iPictoInterface; |
|
84 delete iDummyControl; |
|
85 if ( iPreBuffer ) |
|
86 { |
|
87 delete iPreBuffer; |
|
88 iPreBuffer = NULL; |
|
89 } |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // Gets the text from the current control and puts it into |
|
94 // the edit area. |
|
95 // (other items were commented in a header). |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 EXPORT_C void CFepInputContextFieldJp::SetTextL( |
|
99 const TFepInputContextFieldData& aData ) |
|
100 { |
|
101 |
|
102 if ( iConversionOffset >= 0 ) |
|
103 { |
|
104 // Nothing is done at conversion. |
|
105 return; |
|
106 } |
|
107 |
|
108 if ( aData.iCmd == EPeninputICFInitial ) |
|
109 { |
|
110 iPreConversionData.iRect = aData.iRect; |
|
111 iPreConversionData.iCursorVisibility = aData.iCursorVisibility; |
|
112 iPreConversionData.iCursorSelVisible = aData.iCursorSelVisible; |
|
113 } |
|
114 CFepInputContextField::SetTextL( aData ); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // Start only |
|
119 // (other items were commented in a header). |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C void CFepInputContextFieldJp::StartInlineL() |
|
123 { |
|
124 __ASSERT_DEBUG( ( iConversionOffset < 0 ), |
|
125 User::Panic( KPeninputICFJp, EPanicICFJpStartInlineAlready ) ); |
|
126 |
|
127 // Set Text and Cursor and Region |
|
128 const TInt cursorLowPos = iSelectedCompositionText.LowerPos(); |
|
129 const TInt linehead = iRelativePos; |
|
130 iConversionOffset = cursorLowPos; |
|
131 iConversionArea.SetSelection( iConversionOffset, iConversionOffset ); |
|
132 |
|
133 if ( iConvertingState == ETransitoryInputAreaNextSegmentWait ) |
|
134 { |
|
135 // It exists next transitory input area, |
|
136 // becase of the multi segment in transitory input area |
|
137 SetDisplayData( linehead, linehead + iPreDisplayTextOffset ); |
|
138 iPreDisplayTextOffset = iDisplayTextOffset; |
|
139 } |
|
140 |
|
141 iPreConversionData.iCurSel = iSelectedCompositionText; |
|
142 iPreConversionData.iLength = iBuffer->Des().Length(); |
|
143 iPreBuffer = iBuffer->Des().AllocL(); |
|
144 iPreConversionData.iText.Set( *iPreBuffer ); |
|
145 iConvertingState = ETransitoryInputAreaStandby; |
|
146 |
|
147 const TInt newLinehead = Max( iBuffer->Left( |
|
148 cursorLowPos ).LocateReverse( |
|
149 CEditableText::EParagraphDelimiter ) + 1, |
|
150 0 ); |
|
151 if ( linehead != newLinehead ) |
|
152 { |
|
153 SetDisplayData( newLinehead, newLinehead ); |
|
154 } |
|
155 } |
|
156 |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // Update always replace. |
|
160 // (other items were commented in a header). |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 EXPORT_C void CFepInputContextFieldJp::UpdateInlineL( TDesC& aText, |
|
164 const TInt aDivisionPoint, |
|
165 const TTransitoryInputAreaState aState |
|
166 /*=ETransitoryInputAreaConverting*/ ) |
|
167 { |
|
168 __ASSERT_DEBUG( ( iConversionOffset >= 0 ), |
|
169 User::Panic( KPeninputICFJp, EPanicICFJpUpdateInlineNotReady ) ); |
|
170 |
|
171 const TInt replaceLen = iConversionArea.Length() |
|
172 + iSelectedCompositionText.Length(); |
|
173 const TInt textLen = aText.Length(); |
|
174 const TInt linehead = iRelativePos; |
|
175 const TInt cursorPosition = ( aDivisionPoint < 0 ) |
|
176 ? Max( iSelectedCompositionText.LowerPos() |
|
177 + textLen - replaceLen, linehead ) |
|
178 : iConversionOffset + aDivisionPoint; |
|
179 |
|
180 // Set Region |
|
181 iConversionArea.SetSelection( iConversionOffset + textLen, |
|
182 iConversionOffset ); |
|
183 |
|
184 // Set Text |
|
185 if ( iBuffer ) |
|
186 { |
|
187 // Replace |
|
188 iBuffer->Des().Replace( iConversionOffset, replaceLen, aText ); |
|
189 } |
|
190 else |
|
191 { |
|
192 // Insert |
|
193 iBuffer = HBufC::NewL( Max( replaceLen, textLen ) ); |
|
194 iBuffer->Des().Copy( aText ); |
|
195 } |
|
196 |
|
197 iConvertingState = aState; |
|
198 DoUpdateInline( cursorPosition, aDivisionPoint ); |
|
199 } |
|
200 |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // Commit |
|
204 // (other items were commented in a header). |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 EXPORT_C void CFepInputContextFieldJp::CommitInlineL() |
|
208 { |
|
209 __ASSERT_DEBUG( ( iConversionOffset >= 0 ), |
|
210 User::Panic( KPeninputICFJp, EPanicICFJpCommitInlineNotReady ) ); |
|
211 |
|
212 // Set next conversion starting position |
|
213 const TInt nextPosition = ( iDivisionPoint < 0 ) |
|
214 ? iConversionArea.HigherPos() |
|
215 : iConversionArea.LowerPos() + iDivisionPoint; |
|
216 |
|
217 const TInt nextTransitoryInputLength = ( iDivisionPoint > 0 ) |
|
218 ? iConversionArea.Length() - iDivisionPoint |
|
219 : 0; |
|
220 const TTransitoryInputAreaState state = ( nextTransitoryInputLength > 0 ) |
|
221 ? ETransitoryInputAreaNextSegmentWait |
|
222 : ETransitoryInputAreaStandby; |
|
223 |
|
224 // Initialize |
|
225 iPreDisplayTextOffset = iDisplayTextOffset; |
|
226 ResetConversion( state, nextPosition ); |
|
227 ResetInputContextFieldDataL( EFalse ); |
|
228 } |
|
229 |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // Complete |
|
233 // (other items were commented in a header). |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 EXPORT_C void CFepInputContextFieldJp::CompleteInlineL() |
|
237 { |
|
238 __ASSERT_DEBUG( ( iConversionOffset >= 0 ), |
|
239 User::Panic( KPeninputICFJp, EPanicICFJpCommitInlineNotReady ) ); |
|
240 |
|
241 // Initialize |
|
242 ResetConversion( ETransitoryInputAreaStandby, iConversionOffset ); |
|
243 ResetInputContextFieldDataL( EFalse ); |
|
244 } |
|
245 |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // Cancel |
|
249 // For synchronization with Edwin, Call SetTextL() after this function. |
|
250 // (other items were commented in a header). |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 EXPORT_C void CFepInputContextFieldJp::CancelInlineL() |
|
254 { |
|
255 if ( iConversionOffset < 0 ) |
|
256 { |
|
257 return; |
|
258 } |
|
259 |
|
260 ResetConversion( ETransitoryInputAreaStandby, iConversionOffset ); |
|
261 ResetInputContextFieldDataL( ETrue ); |
|
262 } |
|
263 |
|
264 |
|
265 // --------------------------------------------------------------------------- |
|
266 // Set cursor position on context field. |
|
267 // aPosition is the value when the head of an unconfirmed string is 0. |
|
268 // (other items were commented in a header). |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 EXPORT_C void CFepInputContextFieldJp::SetCursorPosition( |
|
272 const TInt aPosition ) |
|
273 { |
|
274 __ASSERT_DEBUG( ( iConversionOffset >= 0 ), |
|
275 User::Panic( KPeninputICFJp, |
|
276 EPanicICFJpCursorPositionNotReady ) ); |
|
277 |
|
278 DoUpdateInline( PositionInArea( aPosition + iConversionOffset, |
|
279 iConversionArea ), iDivisionPoint ); |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // Return one character before cursor position. |
|
284 // (other items were commented in a header). |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 EXPORT_C TChar CFepInputContextFieldJp::CharacterOnCursor() |
|
288 { |
|
289 const TInt cursorPos = iSelectedCompositionText.iCursorPos; |
|
290 |
|
291 return ( ( iBuffer && cursorPos > 0 ) && ( iConversionOffset < 0 ) ) |
|
292 ? (TChar)( ( iBuffer->Mid( cursorPos - 1, 1 ) )[0] ) |
|
293 : TChar( KNoChar ); |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------------------------- |
|
297 // Return one character before cursor position moving aMovingIndex. |
|
298 // (other items were commented in a header). |
|
299 // --------------------------------------------------------------------------- |
|
300 // |
|
301 EXPORT_C TChar CFepInputContextFieldJp::CharacterAroundCursor( |
|
302 const TInt aMovingIndex ) |
|
303 { |
|
304 const TInt cursorPos = iSelectedCompositionText.iCursorPos + aMovingIndex; |
|
305 |
|
306 return ( ( iBuffer ) |
|
307 && ( iConversionOffset < 0 ) |
|
308 && ( cursorPos > 0 ) |
|
309 && ( cursorPos <= iBuffer->Length() ) ) |
|
310 ? (TChar)( ( iBuffer->Mid( cursorPos - 1, 1 ) )[0] ) |
|
311 : TChar( KNoChar ); |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // Return cursor position |
|
316 // (other items were commented in a header). |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 EXPORT_C TInt CFepInputContextFieldJp::CursorPosition() const |
|
320 { |
|
321 return iSelectedCompositionText.iCursorPos - iConversionOffset; |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------------------------- |
|
325 // Return dividing position |
|
326 // (other items were commented in a header). |
|
327 // --------------------------------------------------------------------------- |
|
328 // |
|
329 EXPORT_C TInt CFepInputContextFieldJp::DivisionPoint() const |
|
330 { |
|
331 return iDivisionPoint; |
|
332 } |
|
333 |
|
334 // --------------------------------------------------------------------------- |
|
335 // C++ default constructor can NOT contain any code, that might leave. |
|
336 // --------------------------------------------------------------------------- |
|
337 // |
|
338 CFepInputContextFieldJp::CFepInputContextFieldJp( TRect aRect, |
|
339 CFepUiLayout* aUiLayout, |
|
340 TInt aControlId ): |
|
341 CFepInputContextField(aRect,aUiLayout,aControlId), |
|
342 iConversionOffset(-1), |
|
343 iDivisionPoint(-1), |
|
344 iConversionArea( 0, 0 ), |
|
345 iConvertingState(ETransitoryInputAreaStandby) |
|
346 { |
|
347 SetControlType(ECtrlInputContextArea); |
|
348 iPreConversionData.iCmd = EPeninputICFInitial; |
|
349 iPreConversionData.iStartPos = 0; |
|
350 iPreConversionData.iMidPos = -1; |
|
351 } |
|
352 |
|
353 // --------------------------------------------------------------------------- |
|
354 // Symbian 2nd phase constructor can leave. |
|
355 // --------------------------------------------------------------------------- |
|
356 // |
|
357 void CFepInputContextFieldJp::ConstructL() |
|
358 { |
|
359 BaseConstructL(); |
|
360 |
|
361 iDummyControl = new (ELeave) CCoeControl(); |
|
362 iPictoInterface = CAknPictographInterface::NewL( *iDummyControl, *this ); |
|
363 |
|
364 TCallBack callback( StaticPictographCallBack, this ); |
|
365 SetPictographCallBackL( callback ); |
|
366 } |
|
367 |
|
368 // --------------------------------------------------------------------------- |
|
369 // Draws the text conversion |
|
370 // (other items were commented in a header). |
|
371 // --------------------------------------------------------------------------- |
|
372 // |
|
373 void CFepInputContextFieldJp::DrawConversion() |
|
374 { |
|
375 const TInt displayOffset = iRelativePos + iDisplayTextOffset; |
|
376 const TInt lowPosition = Max( iConversionArea.LowerPos() - displayOffset, |
|
377 0 ); |
|
378 const TInt highPosition = Min( iConversionArea.HigherPos() - displayOffset, |
|
379 iDisplayText.Length() ); |
|
380 const TInt divisionPosition = Max( iConversionArea.LowerPos() |
|
381 + iDivisionPoint |
|
382 - displayOffset, |
|
383 0 ); |
|
384 |
|
385 // Draw |
|
386 if ( iDivisionPoint > 0 && highPosition > 0 ) |
|
387 { |
|
388 // Draw the conversion data. |
|
389 DoDrawConversion( lowPosition, divisionPosition, |
|
390 EFirstTargetColors ); |
|
391 |
|
392 // Draw the next conversion data. |
|
393 DoDrawConversion( divisionPosition, highPosition, |
|
394 ETransitoryInputAreaColors ); |
|
395 } |
|
396 else |
|
397 { |
|
398 // Draw the conversion data. |
|
399 DoDrawConversion( lowPosition, highPosition, |
|
400 ETransitoryInputAreaColors ); |
|
401 } |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // Draws the text conversion( main frame ) |
|
406 // (other items were commented in a header). |
|
407 // --------------------------------------------------------------------------- |
|
408 // |
|
409 void CFepInputContextFieldJp::DoDrawConversion( const TInt aStartPos, |
|
410 const TInt aEndPos, |
|
411 const TContextFieldDrawColorJp aConversion ) |
|
412 { |
|
413 if ( !iFont || iInDragging ) |
|
414 { |
|
415 // no draw |
|
416 return; |
|
417 } |
|
418 |
|
419 CFbsBitGc* gc = static_cast<CFbsBitGc*>( BitGc() ); |
|
420 TRect converseRect = Rect(); |
|
421 const TInt baseLine = iFont->AscentInPixels()/2 + converseRect.Height()/2; |
|
422 |
|
423 //The conversion rectangular sets |
|
424 converseRect.iTl.iX = PositionInWindow( aStartPos ).iX; |
|
425 converseRect.iBr.iX = |
|
426 ( PositionInWindow( aEndPos ).iX > converseRect.iBr.iX ) |
|
427 ? converseRect.iBr.iX : PositionInWindow( aEndPos ).iX; |
|
428 converseRect.iTl.iY += baseLine - ( iFont->AscentInPixels() |
|
429 + KConversionRectMarginY ); |
|
430 converseRect.iBr.iY += baseLine + iFont->DescentInPixels() |
|
431 + KConversionRectMarginY - Rect().Height(); |
|
432 const TInt conversionBaseLine = baseLine + Rect().iTl.iY |
|
433 - converseRect.iTl.iY; |
|
434 |
|
435 // draw selection by inverting colors in the selected text rectancle |
|
436 gc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
437 gc->SetPenSize( PenSize() ); |
|
438 |
|
439 // Draw pen color and brush color select |
|
440 switch ( aConversion ) |
|
441 { |
|
442 case EFirstTargetColors: |
|
443 { |
|
444 const TRgb KTargetBgColor = AKN_LAF_COLOR_STATIC(210); |
|
445 gc->SetPenColor( BkColor() ); |
|
446 gc->SetBrushColor( KTargetBgColor ); |
|
447 } |
|
448 break; |
|
449 case ETransitoryInputAreaColors: |
|
450 { |
|
451 const TRgb KTransitoryBgColor = AKN_LAF_COLOR_STATIC(244); |
|
452 gc->SetPenColor( PenColor() ); |
|
453 gc->SetBrushColor( KTransitoryBgColor ); |
|
454 } |
|
455 break; |
|
456 default: |
|
457 break; |
|
458 } |
|
459 |
|
460 // draw text |
|
461 TPtrC ptr(iDisplayText.Mid( aStartPos, aEndPos - aStartPos )); |
|
462 gc->DrawText( ptr, |
|
463 converseRect, |
|
464 conversionBaseLine, |
|
465 CGraphicsContext::ELeft ); |
|
466 |
|
467 if (iPictoInterface) |
|
468 { |
|
469 iPictoInterface->Interface()->DrawPictographsInText( |
|
470 *gc, *iFont, ptr, converseRect, |
|
471 conversionBaseLine, CGraphicsContext::ELeft, KGapLeftOfEachLine ); |
|
472 } |
|
473 } |
|
474 |
|
475 // --------------------------------------------------------------------------- |
|
476 // Reculculate offset of context field when cursor position move. |
|
477 // (other items were commented in a header). |
|
478 // --------------------------------------------------------------------------- |
|
479 // |
|
480 void CFepInputContextFieldJp::DoUpdateInline( const TInt aCursorPosition, |
|
481 const TInt aDivisionPoint ) |
|
482 { |
|
483 __ASSERT_DEBUG( ( iConversionOffset >= 0 ), |
|
484 User::Panic( KPeninputICFJp, |
|
485 EPanicICFJpDoUpdateInlineNotReady ) ); |
|
486 |
|
487 // Set Cursor and Region |
|
488 SetCursorVisible( EFalse, EFalse ); |
|
489 iDivisionPoint = aDivisionPoint; |
|
490 iSelectedCompositionText.SetSelection( aCursorPosition, aCursorPosition ); |
|
491 |
|
492 CalculateDisplayTransitoryText(); |
|
493 |
|
494 iInsertionPoint->SetPosition( PositionOfInsertionPointOnWindow() ); |
|
495 if ( iDivisionPoint < 0 ) |
|
496 { |
|
497 SetCursorVisible( ETrue, ETrue ); |
|
498 } |
|
499 Draw(); |
|
500 UpdateArea(Rect(),EFalse); |
|
501 } |
|
502 |
|
503 // --------------------------------------------------------------------------- |
|
504 // Calculate display text offset |
|
505 // (other items were commented in a header). |
|
506 // --------------------------------------------------------------------------- |
|
507 // |
|
508 void CFepInputContextFieldJp::CalculateDisplayTransitoryText() |
|
509 { |
|
510 if( !iBuffer || !iFont || ( iConversionOffset < 0 ) ) |
|
511 { |
|
512 // Nothing is done at no-buffer or no-font or non-converting state. |
|
513 return; |
|
514 } |
|
515 |
|
516 // Check the cursor or dividing point. |
|
517 // These valid are on Editor, and not using any offset. |
|
518 const TInt conversionOffset = iConversionOffset; |
|
519 const TInt divisionPoint = conversionOffset + iDivisionPoint; |
|
520 const TInt conversionEnd = iConversionArea.HigherPos(); |
|
521 const TInt icfWidth = iCorrectedRect.Width(); |
|
522 const TInt linehead = iRelativePos; |
|
523 const TInt cursorPosition = iSelectedCompositionText.iCursorPos; |
|
524 |
|
525 TInt displayOffset = iRelativePos + iDisplayTextOffset; |
|
526 TInt cursorPos = cursorPosition; |
|
527 TInt endPos = cursorPos; |
|
528 TBool leftMarginX = EFalse; |
|
529 TBool rightMarginX = EFalse; |
|
530 const TInt pixels = BufferWidthInPixels( displayOffset, conversionEnd ); |
|
531 |
|
532 if ( iDivisionPoint < 0 ) |
|
533 { |
|
534 // Non conversion |
|
535 if ( cursorPos == conversionEnd ) |
|
536 { |
|
537 // Append to transitory input area |
|
538 leftMarginX = ETrue; |
|
539 rightMarginX = EFalse; |
|
540 } |
|
541 else |
|
542 { |
|
543 // Insert to transitory input area |
|
544 leftMarginX = ETrue; |
|
545 rightMarginX = ( pixels > icfWidth ) ? ETrue : EFalse; |
|
546 } |
|
547 } |
|
548 else |
|
549 { |
|
550 // Conversion |
|
551 switch ( iConvertingState ) |
|
552 { |
|
553 case ETransitoryInputAreaConverting: |
|
554 cursorPos = conversionOffset; |
|
555 endPos = divisionPoint; |
|
556 leftMarginX = EFalse; |
|
557 rightMarginX = EFalse; |
|
558 break; |
|
559 case ETransitoryInputAreaSwitching: |
|
560 cursorPos = divisionPoint; |
|
561 endPos = cursorPos; |
|
562 leftMarginX = ETrue; |
|
563 rightMarginX = ( pixels > icfWidth ) ? ETrue : EFalse; |
|
564 break; |
|
565 default: |
|
566 break; |
|
567 } |
|
568 } |
|
569 |
|
570 TInt cursorPixels = BufferWidthInPixels( displayOffset, endPos ); |
|
571 const TInt rightMaxPixels = ( rightMarginX ) |
|
572 ? icfWidth |
|
573 - iFont->MaxNormalCharWidthInPixels() |
|
574 * KConversionRightMarginX |
|
575 : icfWidth; |
|
576 |
|
577 // Right Check by Pixels |
|
578 while ( rightMaxPixels < cursorPixels ) |
|
579 { |
|
580 // Too right |
|
581 ++displayOffset; |
|
582 cursorPixels = BufferWidthInPixels( displayOffset, endPos ); |
|
583 } |
|
584 |
|
585 const TInt leftMinPos = ( leftMarginX ) |
|
586 ? displayOffset + KConversionLeftMarginX |
|
587 : displayOffset; |
|
588 |
|
589 // Left Check by Position |
|
590 if ( cursorPos < leftMinPos ) |
|
591 { |
|
592 // Too left |
|
593 displayOffset = ( leftMarginX ) ? cursorPos - KConversionLeftMarginX |
|
594 : cursorPos; |
|
595 } |
|
596 |
|
597 displayOffset = Max( displayOffset, linehead ); |
|
598 TInt lineEnd = iBuffer->Mid( cursorPosition ).Locate( |
|
599 CEditableText::EParagraphDelimiter ); |
|
600 lineEnd = lineEnd < 0? iBuffer->Des().Length() : lineEnd + cursorPosition; |
|
601 |
|
602 SetDisplayData( linehead, displayOffset ); |
|
603 iDisplayText.Set( iBuffer->Mid( displayOffset, lineEnd - displayOffset ) ); |
|
604 } |
|
605 |
|
606 // --------------------------------------------------------------------------- |
|
607 // Calculate width in pixels of selecting area in iBuffer. |
|
608 // (other items were commented in a header). |
|
609 // --------------------------------------------------------------------------- |
|
610 // |
|
611 TInt CFepInputContextFieldJp::BufferWidthInPixels( TInt aStartPos, |
|
612 TInt aEndPos ) const |
|
613 { |
|
614 const TInt length = Max( aEndPos - aStartPos, 0 ); |
|
615 |
|
616 return iFont->TextWidthInPixels( iBuffer->Mid( aStartPos, length ) ); |
|
617 } |
|
618 |
|
619 // --------------------------------------------------------------------------- |
|
620 // Set member data for display. |
|
621 // (other items were commented in a header). |
|
622 // --------------------------------------------------------------------------- |
|
623 // |
|
624 void CFepInputContextFieldJp::SetDisplayData( TInt aLineHead, |
|
625 TInt aDisplayOffset ) |
|
626 { |
|
627 const TInt cursor = iSelectedCompositionText.iCursorPos - aLineHead; |
|
628 |
|
629 iDisplayTextOffset = Max( aDisplayOffset - aLineHead, 0 ); |
|
630 iRelativePos = aLineHead; |
|
631 iDisplayTextCurSel.SetSelection( cursor, cursor ); |
|
632 } |
|
633 |
|
634 // --------------------------------------------------------------------------- |
|
635 // Reset member data of parent class. |
|
636 // (other items were commented in a header). |
|
637 // --------------------------------------------------------------------------- |
|
638 // |
|
639 void CFepInputContextFieldJp::ResetInputContextFieldDataL( TBool aDrawFlag ) |
|
640 { |
|
641 |
|
642 if ( aDrawFlag ) |
|
643 { |
|
644 CFepInputContextField::SetTextL( iPreConversionData ); |
|
645 } |
|
646 else |
|
647 { |
|
648 iSelectedCompositionText = iPreConversionData.iCurSel; |
|
649 TPtr ptr = iBuffer->Des(); |
|
650 ptr = iPreConversionData.iText; |
|
651 SetCursorVisible( iPreConversionData.iCursorVisibility, |
|
652 iPreConversionData.iCursorSelVisible ); |
|
653 iInsertionPoint->SetPosition( PositionOfInsertionPointOnWindow() ); |
|
654 } |
|
655 delete iPreBuffer; |
|
656 iPreBuffer = NULL; |
|
657 } |
|
658 |
|
659 // --------------------------------------------------------------------------- |
|
660 // Reset member data of transitory input area. |
|
661 // (other items were commented in a header). |
|
662 // --------------------------------------------------------------------------- |
|
663 // |
|
664 void CFepInputContextFieldJp::ResetConversion( |
|
665 TTransitoryInputAreaState aState, |
|
666 TInt aPosition ) |
|
667 { |
|
668 iConversionOffset = -1; |
|
669 iDivisionPoint = -1; |
|
670 iConvertingState = aState; |
|
671 iConversionArea.SetSelection( aPosition, aPosition ); |
|
672 } |
|
673 |
|
674 |
|
675 // --------------------------------------------------------------------------- |
|
676 // The argument returns whether it is the right side from transitory input |
|
677 // area. |
|
678 // (other items were commented in a header). |
|
679 // --------------------------------------------------------------------------- |
|
680 // |
|
681 TBool CFepInputContextFieldJp::IsRightFromConversion( TInt aX ) const |
|
682 { |
|
683 const TInt displayOffset = iRelativePos + iDisplayTextOffset; |
|
684 const TInt xPosOffset = aX - iCorrectedRect.iTl.iX; |
|
685 const TInt highPosOffset = iConversionArea.HigherPos() - displayOffset; |
|
686 const TInt highPosPixel = iFont->TextWidthInPixels( |
|
687 iDisplayText.Left( highPosOffset ) ); |
|
688 const TBool pointFlag = ( xPosOffset > highPosPixel ) ? ETrue : EFalse; |
|
689 const TBool curposFlag = ( CursorPosition() == iConversionArea.Length() ) |
|
690 ? ETrue : EFalse; |
|
691 |
|
692 return ( pointFlag && curposFlag && ( iDivisionPoint < 0 ) ) |
|
693 ? ETrue |
|
694 : EFalse; |
|
695 } |
|
696 |
|
697 |
|
698 // --------------------------------------------------------------------------- |
|
699 // From class CFepUiBaseCtrl |
|
700 // Handle pointer up event |
|
701 // (other items were commented in a header). |
|
702 // --------------------------------------------------------------------------- |
|
703 // |
|
704 CFepUiBaseCtrl* CFepInputContextFieldJp::HandlePointerUpEventL( |
|
705 const TPoint& aPoint ) |
|
706 { |
|
707 if ( iConversionOffset < 0 ) |
|
708 { |
|
709 // Non-conversion |
|
710 // Behave the common function |
|
711 return ( !CFepInputContextField::HandlePointerUpEventL(aPoint) ) ? |
|
712 NULL : this; |
|
713 } |
|
714 |
|
715 // Setting of derivation origin |
|
716 CFepUiBaseCtrl::HandlePointerUpEventL(aPoint); |
|
717 iScrolling = EFalse; |
|
718 |
|
719 // Does Freely pointer event |
|
720 if( iPreCaptureCtrl ) |
|
721 { |
|
722 // In case of not being, it makes and does freely. |
|
723 iPreCaptureCtrl->CapturePointer(); |
|
724 } |
|
725 else |
|
726 { |
|
727 // In case of being, it does freely. |
|
728 CapturePointer( EFalse ); |
|
729 } |
|
730 |
|
731 if ( iAllCompleteFlag ) |
|
732 { |
|
733 iAllCompleteFlag = IsRightFromConversion( aPoint.iX ); |
|
734 } |
|
735 |
|
736 const TInt eventType = ( iAllCompleteFlag ) ? EEventIcfCompleteAll |
|
737 : EEventIcfPointerUp; |
|
738 TInt cursorPos = PositionInDisplayText( aPoint.iX ); |
|
739 SetPositionOfInsertionPointInBuffer( cursorPos ); |
|
740 |
|
741 // selection was dragged inside visible buffer -> update selection |
|
742 TCursorSelection area = iConversionArea; |
|
743 if ( iConvertingState == ETransitoryInputAreaSwitching ) |
|
744 { |
|
745 // At least one character are the state that has been selected. |
|
746 area.iAnchorPos += KConversionSelectingMargin; |
|
747 } |
|
748 const TInt newPosition |
|
749 = PositionInArea( iSelectedCompositionText.iCursorPos, area ); |
|
750 const TInt pos = newPosition - iConversionOffset; |
|
751 if ( iDivisionPoint < 0 ) |
|
752 { |
|
753 DoUpdateInline( newPosition, |
|
754 ( iDivisionPoint < 0 ) ? iDivisionPoint : pos ); |
|
755 } |
|
756 |
|
757 TPtrC position((TUint16*) &pos ); |
|
758 ReportEvent( eventType, position ); |
|
759 |
|
760 return this; |
|
761 } |
|
762 |
|
763 // --------------------------------------------------------------------------- |
|
764 // From class CFepUiBaseCtrl |
|
765 // Handle pointer down event |
|
766 // (other items were commented in a header). |
|
767 // --------------------------------------------------------------------------- |
|
768 // |
|
769 CFepUiBaseCtrl* CFepInputContextFieldJp::HandlePointerDownEventL( |
|
770 const TPoint& aPoint ) |
|
771 { |
|
772 if ( iConversionOffset < 0 ) |
|
773 { |
|
774 // Non-conversion |
|
775 // Behave the common function |
|
776 return ( !CFepInputContextField::HandlePointerDownEventL(aPoint) ) ? |
|
777 NULL : this; |
|
778 } |
|
779 |
|
780 if ( ( iDivisionPoint >= 0 ) |
|
781 && ( iConvertingState == ETransitoryInputAreaConverting ) ) |
|
782 { |
|
783 // Nothing is done at converting state.. |
|
784 return this; |
|
785 } |
|
786 |
|
787 // Conversion |
|
788 CFepUiBaseCtrl::HandlePointerDownEventL( aPoint ); |
|
789 iAllCompleteFlag = IsRightFromConversion( aPoint.iX ); |
|
790 iScrolling = EFalse; |
|
791 |
|
792 // Set cursor position |
|
793 iScrolling = EFalse; |
|
794 iPreCaptureCtrl = CapturePointer(); |
|
795 |
|
796 return this; |
|
797 } |
|
798 |
|
799 |
|
800 // --------------------------------------------------------------------------- |
|
801 // From class CFepUiBaseCtrl |
|
802 // Handle pointer move event |
|
803 // (other items were commented in a header). |
|
804 // --------------------------------------------------------------------------- |
|
805 // |
|
806 CFepUiBaseCtrl* CFepInputContextFieldJp::HandlePointerMoveEventL( |
|
807 const TPoint& aPoint ) |
|
808 { |
|
809 |
|
810 if ( iConversionOffset < 0 ) |
|
811 { |
|
812 // Non-conversion |
|
813 // Behave the common function |
|
814 return ( !CFepLayoutEditAreaBase::HandlePointerMoveEventL(aPoint) ) ? |
|
815 NULL : this; |
|
816 } |
|
817 |
|
818 if( !PointerDown() || iDimmed || ( ( iDivisionPoint >= 0 ) |
|
819 && ( iConvertingState == ETransitoryInputAreaConverting ) ) ) |
|
820 { |
|
821 // Nothing is done at no-pointerdown, no-dimm, converting state.. |
|
822 return this; |
|
823 } |
|
824 |
|
825 // Updating by the drug operation. |
|
826 const TInt displayOffset = iRelativePos + iDisplayTextOffset; |
|
827 const TInt newPos = PositionInArea( PositionInDisplayText( aPoint.iX ) |
|
828 + displayOffset, |
|
829 iConversionArea ); |
|
830 const TBool checkOfPosition = |
|
831 ( newPos != iSelectedCompositionText.iCursorPos ) |
|
832 ? ETrue : EFalse; |
|
833 |
|
834 if ( iAllCompleteFlag ) |
|
835 { |
|
836 iAllCompleteFlag = IsRightFromConversion( aPoint.iX ); |
|
837 } |
|
838 |
|
839 if( checkOfPosition ) |
|
840 { |
|
841 // Updating when cursor position or dividing position changes. |
|
842 // Even if the pointer moves, the cursor position is never changed. |
|
843 TCursorSelection area = iConversionArea; |
|
844 if ( iConvertingState == ETransitoryInputAreaSwitching ) |
|
845 { |
|
846 // At least one character are the state that has been selected. |
|
847 area.iAnchorPos += KConversionSelectingMargin; |
|
848 } |
|
849 const TInt dividingPoint = PositionInArea( newPos, area ) |
|
850 - iConversionOffset; |
|
851 DoUpdateInline( newPos, ( iDivisionPoint < 0 ) |
|
852 ? iDivisionPoint |
|
853 : dividingPoint ); |
|
854 } |
|
855 |
|
856 return this; |
|
857 } |
|
858 |
|
859 // --------------------------------------------------------------------------- |
|
860 // From class CFepLayoutEditAreaBase |
|
861 // Draws the text into the given graphic context |
|
862 // (other items were commented in a header). |
|
863 // --------------------------------------------------------------------------- |
|
864 // |
|
865 void CFepInputContextFieldJp::DrawContent( CBitmapContext* aGc, |
|
866 const TRect& aRect ) |
|
867 { |
|
868 if ( iConvertingState == ETransitoryInputAreaNextSegmentWait ) |
|
869 { |
|
870 return; |
|
871 } |
|
872 if ( ( iConversionOffset < 0 ) || !iBuffer || !iFont || iInDragging ) |
|
873 { |
|
874 // Non-conversion, no-buffer, no-font, no-dragging |
|
875 // Behave the common function |
|
876 CFepLayoutEditAreaBase::DrawContent( aGc, aRect ); |
|
877 |
|
878 if (iPictoInterface) |
|
879 { |
|
880 TRect editRect = Rect(); |
|
881 aGc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
882 aGc->UseFont( iFont ); |
|
883 aGc->SetPenColor( iTextColor ); |
|
884 const TInt baseLine = iFont->AscentInPixels()/2 + editRect.Height()/2; |
|
885 |
|
886 iPictoInterface->Interface()->DrawPictographsInText( |
|
887 *aGc, *iFont, iDisplayText, editRect, |
|
888 baseLine, CGraphicsContext::ELeft, KGapLeftOfEachLine ); |
|
889 |
|
890 aGc->DiscardFont(); |
|
891 } |
|
892 return; |
|
893 } |
|
894 |
|
895 TRect editRect = Rect(); |
|
896 if( aRect.Intersects( editRect ) ) |
|
897 { |
|
898 // draw text |
|
899 // set brush invisible so the background |
|
900 // of the edit area does not get painted white |
|
901 const TInt baseLine = iFont->AscentInPixels()/2 + editRect.Height()/2; |
|
902 aGc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
903 aGc->UseFont( iFont ); |
|
904 aGc->SetPenColor( iTextColor ); |
|
905 aGc->DrawText( iDisplayText, |
|
906 editRect, |
|
907 baseLine, |
|
908 CGraphicsContext::ELeft, |
|
909 KGapLeftOfEachLine ); |
|
910 if (iPictoInterface) |
|
911 { |
|
912 iPictoInterface->Interface()->DrawPictographsInText( |
|
913 *aGc, *iFont, iDisplayText, editRect, |
|
914 baseLine, CGraphicsContext::ELeft, KGapLeftOfEachLine ); |
|
915 } |
|
916 |
|
917 if( iConversionOffset >= 0 ) |
|
918 { |
|
919 // Draw text conversion |
|
920 DrawConversion(); |
|
921 } |
|
922 |
|
923 iInsertionPoint->Draw( aGc, ETrue ); |
|
924 |
|
925 aGc->DiscardFont(); |
|
926 } |
|
927 } |
|
928 |
|
929 void CFepInputContextFieldJp::DrawPictographArea() |
|
930 { |
|
931 if ( iPictoCallBack.iFunction ) |
|
932 { |
|
933 iPictoCallBack.CallBack(); |
|
934 } |
|
935 } |
|
936 |
|
937 void CFepInputContextFieldJp::SetPictographCallBackL( TCallBack& aCallBack ) |
|
938 { |
|
939 iPictoCallBack = aCallBack; |
|
940 } |
|
941 |
|
942 // Callback for doing a redraw when animating pictographs |
|
943 TInt CFepInputContextFieldJp::StaticPictographCallBack( TAny* aPtr ) |
|
944 { |
|
945 CFepInputContextFieldJp* self = static_cast<CFepInputContextFieldJp*>( aPtr ); |
|
946 self->PictographCallBack(); |
|
947 return KErrNone; |
|
948 } |
|
949 |
|
950 void CFepInputContextFieldJp::PictographCallBack() |
|
951 { |
|
952 Draw(); |
|
953 //UpdateArea(Rect(),EFalse); |
|
954 } |
|
955 |
|
956 // End of File |