javauis/lcdui_akn/lcdui/src/CMIDTextEditorEdwin.cpp
branchRCL_3
changeset 46 4376525cdefb
parent 25 9ac0a0a7da70
child 59 e5618cc85d74
equal deleted inserted replaced
34:71c436fe3ce0 46:4376525cdefb
    19 // INTERNAL INCLUDES
    19 // INTERNAL INCLUDES
    20 #include "CMIDTextEditorEdwin.h"
    20 #include "CMIDTextEditorEdwin.h"
    21 #include "CMIDEdwinUtils.h"
    21 #include "CMIDEdwinUtils.h"
    22 #include "CMIDTextEditorEdwinCustomDraw.h"
    22 #include "CMIDTextEditorEdwinCustomDraw.h"
    23 #include "CMIDEditingStateIndicator.h"
    23 #include "CMIDEditingStateIndicator.h"
       
    24 #include "CMIDDisplayable.h"
    24 
    25 
    25 // EXTERNAL INCLUDES
    26 // EXTERNAL INCLUDES
    26 #include <MMIDTextEditor.h> // MMIDTextEditorObserver
    27 #include <MMIDTextEditor.h> // MMIDTextEditorObserver
    27 #include <aknextendedinputcapabilities.h>
    28 #include <aknextendedinputcapabilities.h>
    28 #include <AknSettingCache.h>
    29 #include <AknSettingCache.h>
    29 #include <eikedwob.h>
    30 #include <eikedwob.h>
    30 #include <j2me/jdebug.h>
    31 #include <j2me/jdebug.h>
    31 
    32 
       
    33 #ifdef RD_JAVA_S60_RELEASE_9_2
       
    34 #include <AknPriv.hrh>
       
    35 #endif // RD_JAVA_S60_RELEASE_9_2
       
    36 
    32 const TInt KColorOpaque = 255;
    37 const TInt KColorOpaque = 255;
    33 const TInt KCharMinus   = 0x2d;
    38 const TInt KCharMinus   = 0x2d;
    34 
    39 
    35 // ---------------------------------------------------------------------------
    40 // ---------------------------------------------------------------------------
    36 // CMIDTextEditorEdwin::CMIDTextEditorEdwin
    41 // CMIDTextEditorEdwin::CMIDTextEditorEdwin
    37 // ---------------------------------------------------------------------------
    42 // ---------------------------------------------------------------------------
    38 //
    43 //
    39 CMIDTextEditorEdwin::CMIDTextEditorEdwin(CMIDEdwinUtils& aEdwinUtils)
    44 CMIDTextEditorEdwin::CMIDTextEditorEdwin(CMIDEdwinUtils& aEdwinUtils)
    40     : CEikEdwin(),
    45         : CEikEdwin(),
    41       iMultiline(EFalse),
    46         iMultiline(EFalse),
    42       iCursorPosForAction(KErrNotFound),
    47         iCursorPosForAction(KErrNotFound),
    43       iEdwinUtils(aEdwinUtils)
    48         iEdwinUtils(aEdwinUtils)
    44 {
    49 {
    45     DEBUG("CMIDTextEditorEdwin::CMIDTextEditorEdwin +");
    50     DEBUG("CMIDTextEditorEdwin::CMIDTextEditorEdwin +");
    46 
    51 
       
    52 #ifdef RD_JAVA_S60_RELEASE_9_2
       
    53     iPartialVKBOpen = EFalse;
       
    54     iDisplayable = NULL;
       
    55     iJavaAppUi = NULL;
       
    56 #endif // RD_JAVA_S60_RELEASE_9_2
    47     // Set margins to zero
    57     // Set margins to zero
    48     TMargins8 margins;
    58     TMargins8 margins;
    49     margins.SetAllValuesTo(0);
    59     margins.SetAllValuesTo(0);
    50     SetBorderViewMargins(margins);
    60     SetBorderViewMargins(margins);
    51     // Set layout
    61     // Set layout
   170                 // Notify about text change.
   180                 // Notify about text change.
   171                 HandleTextChangedL();
   181                 HandleTextChangedL();
   172                 // Restore cursor's original position.
   182                 // Restore cursor's original position.
   173                 SetCursorPosL(iCursorPosForAction, EFalse);
   183                 SetCursorPosL(iCursorPosForAction, EFalse);
   174             }
   184             }
   175 
       
   176             CleanupStack::PopAndDestroy(oldContent);
   185             CleanupStack::PopAndDestroy(oldContent);
   177         }
   186         }
   178 
   187 
   179         // Update current selection.
   188         // Update current selection.
   180         iSelection = Selection();
   189         iSelection = Selection();
   203 // (other items were commented in the header file)
   212 // (other items were commented in the header file)
   204 // ---------------------------------------------------------------------------
   213 // ---------------------------------------------------------------------------
   205 //
   214 //
   206 TBool CMIDTextEditorEdwin::Traverse(const TKeyEvent& aEvent)
   215 TBool CMIDTextEditorEdwin::Traverse(const TKeyEvent& aEvent)
   207 {
   216 {
   208     TInt cursorPos = CursorPos();
   217     TInt cursorPos = 0;
   209     TBool traverse = EFalse;
   218     TBool traverse = EFalse;
   210 
   219 
   211     if ((aEvent.iCode == EKeyDownArrow) ||
   220     if ((aEvent.iCode == EKeyDownArrow) ||
   212             (aEvent.iScanCode == EStdKeyDownArrow))
   221             (aEvent.iScanCode == EStdKeyDownArrow))
   213     {
   222     {
       
   223         cursorPos = CursorPos();
   214         if (TextLength() == cursorPos)
   224         if (TextLength() == cursorPos)
   215         {
   225         {
   216             traverse = ETrue;
   226             traverse = ETrue;
   217         }
   227         }
   218 
   228 
   219     }
   229     }
   220     else if ((aEvent.iCode == EKeyUpArrow) ||
   230     else if ((aEvent.iCode == EKeyUpArrow) ||
   221              (aEvent.iScanCode == EStdKeyUpArrow))
   231              (aEvent.iScanCode == EStdKeyUpArrow))
   222     {
   232     {
       
   233         cursorPos = CursorPos();
   223         if (cursorPos == 0)
   234         if (cursorPos == 0)
   224         {
   235         {
   225             traverse = ETrue;
   236             traverse = ETrue;
   226         }
   237         }
   227 
   238 
   552                 event |= MMIDTextEditorObserver::EActionDirectionChange;
   563                 event |= MMIDTextEditorObserver::EActionDirectionChange;
   553             }
   564             }
   554             iObserver->NotifyInputAction(event);
   565             iObserver->NotifyInputAction(event);
   555         }
   566         }
   556     }
   567     }
       
   568 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   569     if ((aType == KAknSplitInputEnabled))
       
   570     {
       
   571         // Partial screen keyboard is opened
       
   572         CEikStatusPane* pane = GetStatusPane();
       
   573         if (!iPartialVKBOpen || pane->IsVisible())
       
   574         {
       
   575             // Hide status pane and resize displayable
       
   576             iDisplayable->HandleSplitScreenKeyboard(ETrue);
       
   577             // Preventing from notification when pane is visible, but VKB is
       
   578             // already opened
       
   579             if (iObserver && !iPartialVKBOpen)
       
   580             {
       
   581                 iObserver->NotifyInputAction(
       
   582                     MMIDTextEditorObserver::EActionPartialInputEnabled);
       
   583             }
       
   584             iPartialVKBOpen = ETrue;
       
   585         }
       
   586     }
       
   587     else if ((aType == KAknSplitInputDisabled) && (iPartialVKBOpen))
       
   588     {
       
   589         HandlePartialVKBDisable();
       
   590     }
       
   591 #endif // RD_JAVA_S60_RELEASE_9_2
       
   592 }
       
   593 
       
   594 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   595 // ---------------------------------------------------------------------------
       
   596 // CMIDTextEditorEdwin::FocusLost
       
   597 // (other items were commented in the header file)
       
   598 // ---------------------------------------------------------------------------
       
   599 //
       
   600 void CMIDTextEditorEdwin::FocusLost()
       
   601 {
       
   602     if (iPartialVKBOpen)
       
   603     {
       
   604         DEBUG("Focus LOST - disable VKB");
       
   605         CloseVKB();
       
   606     }
       
   607 }
       
   608 
       
   609 // ---------------------------------------------------------------------------
       
   610 // CMIDTextEditorEdwin::FocusLost
       
   611 // (other items were commented in the header file)
       
   612 // ---------------------------------------------------------------------------
       
   613 //
       
   614 void CMIDTextEditorEdwin::CloseVKB()
       
   615 {
       
   616     CCoeFep* fep = iCoeEnv->Fep();
       
   617     if (fep)
       
   618     {
       
   619         fep->HandleDestructionOfFocusedItem();
       
   620     }
       
   621 }
       
   622 
       
   623 // ---------------------------------------------------------------------------
       
   624 // CMIDTextEditorEdwin::DisablePartialVKB
       
   625 // (other items were commented in the header file)
       
   626 // ---------------------------------------------------------------------------
       
   627 //
       
   628 void CMIDTextEditorEdwin::HandlePartialVKBDisable()
       
   629 {
       
   630     // Partial screen keyboard is closed
       
   631     iPartialVKBOpen = EFalse;
       
   632     // Show status pane if not in fullscreen and resize displayable
       
   633     iDisplayable->HandleSplitScreenKeyboard(EFalse);
       
   634     if (iObserver)
       
   635     {
       
   636         iObserver->NotifyInputAction(
       
   637             MMIDTextEditorObserver::EActionPartialInputDisabled);
       
   638     }
       
   639 }
       
   640 
       
   641 // ---------------------------------------------------------------------------
       
   642 // CMIDTextEditorEdwin::GetStatusPane
       
   643 // (other items were commented in the header file)
       
   644 // ---------------------------------------------------------------------------
       
   645 //
       
   646 CEikStatusPane* CMIDTextEditorEdwin::GetStatusPane()
       
   647 {
       
   648     if (!iJavaAppUi)
       
   649     {
       
   650         iJavaAppUi = java::ui::CoreUiAvkonLcdui::
       
   651                      getInstance().getJavaAknAppUi();
       
   652     }
       
   653     CEikStatusPane* pane = iJavaAppUi->StatusPane();
       
   654     return pane;
       
   655 }
       
   656 #endif // RD_JAVA_S60_RELEASE_9_2
       
   657 
       
   658 // ---------------------------------------------------------------------------
       
   659 // CMIDTextEditorEdwin::GetStatusPane
       
   660 // (other items were commented in the header file)
       
   661 // ---------------------------------------------------------------------------
       
   662 //
       
   663 TInt CMIDTextEditorEdwin::ScrollBarEvent()
       
   664 {
       
   665     TInt event = 0;
       
   666     TInt newVisiblecontentHeight = VisibleContentPosition();
       
   667 
       
   668     // Check if cursor has moved. This must be done because
       
   669     // currently edwin does not report cursor position movement
       
   670     // when text is changed due to user input.
       
   671     if (iVisibleContentHeight != newVisiblecontentHeight)
       
   672     {
       
   673         event |= MMIDTextEditorObserver::EActionScrollbarChange;
       
   674         // Reported, reset here to avoid multiple notifications.
       
   675         iVisibleContentHeight = newVisiblecontentHeight;
       
   676     }
       
   677     return event;
   557 }
   678 }
   558 
   679 
   559 // ---------------------------------------------------------------------------
   680 // ---------------------------------------------------------------------------
   560 // CMIDTextEditorEdwin::HandleEdwinEventL
   681 // CMIDTextEditorEdwin::HandleEdwinEventL
   561 // (other items were commented in the header file)
   682 // (other items were commented in the header file)
   585         switch (aEventType)
   706         switch (aEventType)
   586         {
   707         {
   587         case EEventNavigation:
   708         case EEventNavigation:
   588         {
   709         {
   589             TInt event = MMIDTextEditorObserver::EActionCaretMove;
   710             TInt event = MMIDTextEditorObserver::EActionCaretMove;
   590             TInt newVisiblecontentHeight = VisibleContentPosition();
   711             event |= ScrollBarEvent();
   591 
       
   592             // Check if cursor has moved. This must be done because
       
   593             // currently edwin does not report cursor position movement
       
   594             // when text is changed due to user input.
       
   595             if (iVisibleContentHeight != newVisiblecontentHeight)
       
   596             {
       
   597                 event |= MMIDTextEditorObserver::EActionScrollbarChange;
       
   598                 // Reported, reset here to avoid multiple notifications.
       
   599                 iVisibleContentHeight = newVisiblecontentHeight;
       
   600             }
       
   601 
       
   602             iObserver->NotifyInputAction(event);
   712             iObserver->NotifyInputAction(event);
   603             break;
   713             break;
   604         }
   714         }
   605         case EEventFormatChanged: // Fallthrough
   715         case EEventFormatChanged: // Fallthrough
   606         case EEventTextUpdate:
   716         case EEventTextUpdate:
   615             {
   725             {
   616                 event |= MMIDTextEditorObserver::EActionCaretMove;
   726                 event |= MMIDTextEditorObserver::EActionCaretMove;
   617                 // Reported, reset here to avoid multiple notifications.
   727                 // Reported, reset here to avoid multiple notifications.
   618                 iCursorPosForAction = KErrNotFound;
   728                 iCursorPosForAction = KErrNotFound;
   619             }
   729             }
   620 
   730             event |= ScrollBarEvent();
   621             iObserver->NotifyInputAction(event);
   731             iObserver->NotifyInputAction(event);
   622             break;
   732             break;
   623         }
   733         }
   624         case EEventScroll:
   734         case EEventScroll:
   625         {
   735         {
   671     // Do not handle anything if text's maximum lenght has been reached
   781     // Do not handle anything if text's maximum lenght has been reached
   672     // or if the editor is set to read only state.
   782     // or if the editor is set to read only state.
   673     if (TextLength() >= MaxLength() || IsReadOnly())
   783     if (TextLength() >= MaxLength() || IsReadOnly())
   674     {
   784     {
   675         DEBUG("CMIDTextEditorEdwin::HandleSpecialKeyEventsL -, \
   785         DEBUG("CMIDTextEditorEdwin::HandleSpecialKeyEventsL -, \
   676 max size reached");
   786 max size reached or is read only");
   677 
       
   678         return response;
   787         return response;
   679     }
   788     }
   680 
   789 
   681     TUint sc = aKeyEvent.iScanCode;
   790     TUint sc = aKeyEvent.iScanCode;
   682 
   791 
   960     // that is set when CAknEditorState is constructed. See
  1069     // that is set when CAknEditorState is constructed. See
   961     // CAknEditorState::CAknEditorState in aknedsts.cpp for details.
  1070     // CAknEditorState::CAknEditorState in aknedsts.cpp for details.
   962 
  1071 
   963     SetAknEditorCase(EAknEditorTextCase);
  1072     SetAknEditorCase(EAknEditorTextCase);
   964     SetAknEditorPermittedCaseModes(EAknEditorAllCaseModes);
  1073     SetAknEditorPermittedCaseModes(EAknEditorAllCaseModes);
       
  1074 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1075     SetAknEditorFlags(EAknEditorFlagEnablePartialScreen);
       
  1076 #else
   965     SetAknEditorFlags(EAknEditorFlagDefault);
  1077     SetAknEditorFlags(EAknEditorFlagDefault);
       
  1078 #endif // RD_JAVA_S60_RELEASE_9_2
   966     SetAknEditorSpecialCharacterTable(KErrNotFound);
  1079     SetAknEditorSpecialCharacterTable(KErrNotFound);
   967     SetAknEditorInputMode(EAknEditorTextInputMode);
  1080     SetAknEditorInputMode(EAknEditorTextInputMode);
   968     SetAknEditorAllowedInputModes(EAknEditorAllInputModes);
  1081     SetAknEditorAllowedInputModes(EAknEditorAllInputModes);
   969     SetAknEditorCurrentInputMode(EAknEditorTextInputMode);
  1082     SetAknEditorCurrentInputMode(EAknEditorTextInputMode);
   970     SetAknEditorCurrentCase(EAknEditorTextCase);
  1083     SetAknEditorCurrentCase(EAknEditorTextCase);
  1200 // ---------------------------------------------------------------------------
  1313 // ---------------------------------------------------------------------------
  1201 // CMIDTextEditorEdwin::InitializeL
  1314 // CMIDTextEditorEdwin::InitializeL
  1202 // (other items were commented in the header file)
  1315 // (other items were commented in the header file)
  1203 // ---------------------------------------------------------------------------
  1316 // ---------------------------------------------------------------------------
  1204 //
  1317 //
  1205 void CMIDTextEditorEdwin::InitializeL()
  1318 void CMIDTextEditorEdwin::InitializeL(CMIDDisplayable* aDisplayable)
  1206 {
  1319 {
  1207     DEBUG("CMIDTextEditorEdwin::InitializeL +");
  1320     DEBUG("CMIDTextEditorEdwin::InitializeL +");
  1208 
  1321 
  1209     if (!iInitialized)
  1322     if (!iInitialized)
  1210     {
  1323     {
       
  1324 
       
  1325 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1326         iDisplayable = aDisplayable;
       
  1327 #else
       
  1328         (void)aDisplayable;  // Just to remove a compiler warning
       
  1329 #endif // RD_JAVA_S60_RELEASE_9_2
       
  1330 
  1211         CreateTextViewL();
  1331         CreateTextViewL();
  1212         ActivateL();
  1332         ActivateL();
  1213 
  1333 
  1214         // Set colors here in order to avoid crash when parent
  1334         // Set colors here in order to avoid crash when parent
  1215         // has not been set by CMIDTextEditor.
  1335         // has not been set by CMIDTextEditor.
  1249 {
  1369 {
  1250     DEBUG("CMIDTextEditorEdwin::Uninitialize +");
  1370     DEBUG("CMIDTextEditorEdwin::Uninitialize +");
  1251 
  1371 
  1252     if (iInitialized)
  1372     if (iInitialized)
  1253     {
  1373     {
       
  1374 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1375         iDisplayable = NULL;
       
  1376 #endif // RD_JAVA_S60_RELEASE_9_2
  1254         // Remove focus and hide the editor.
  1377         // Remove focus and hide the editor.
  1255         SetFocus(EFalse);
  1378         SetFocus(EFalse);
  1256         MakeVisible(EFalse);
  1379         MakeVisible(EFalse);
  1257         // Store cursor's current position.
  1380         // Store cursor's current position.
  1258         iCursorPosition = CEikEdwin::CursorPos();
  1381         iCursorPosition = CEikEdwin::CursorPos();