userdict/src/UdictView.cpp
branchRCL_3
changeset 13 261ff9819be3
equal deleted inserted replaced
12:e9f0e1110077 13:261ff9819be3
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:     Japanese user dictionary View class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include  <bldvariant.hrh>
       
    24 #include  "UdictApp.h"
       
    25 #include  "UdictView.h"
       
    26 #include  "UdictModel.h"
       
    27 #include  "UdictModel.inl"
       
    28 #include  "UdictContainer.h"
       
    29 #include  "UdictContainer.inl"
       
    30 #include  "UdictFrm.h"
       
    31 #include  "UserDict.hrh"
       
    32 #include  <userdict.rsg>
       
    33 #include  <aknViewAppUi.h>
       
    34 #include  <aknmessagequerydialog.h>
       
    35 #include  <StringLoader.h>
       
    36 #include  <eikmenub.h>
       
    37 #include  <featmgr.h>
       
    38 #include  <hlplch.h>
       
    39 #include  <aknnotewrappers.h>
       
    40 #include <w32std.h>
       
    41 
       
    42 // CONSTANTS
       
    43 const TUid KViewId = {1}; // UID of View
       
    44 const TInt KMessageBuffSize(64);
       
    45 #if defined(_DEBUG)
       
    46 _LIT(KPanicCatView, "UserDictView");
       
    47 #endif
       
    48 
       
    49 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CUserDictView::NewLC
       
    53 // Two-phased constructor.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CUserDictView* CUserDictView::NewLC(CUserDictModel& aModel)
       
    57     {
       
    58     CUserDictView* self = new (ELeave) CUserDictView(aModel);
       
    59     CleanupStack::PushL(self);
       
    60     self->ConstructL();
       
    61 
       
    62     return self;
       
    63     }
       
    64 
       
    65 // Destructor
       
    66 CUserDictView::~CUserDictView()
       
    67     {
       
    68     if (iContainer)
       
    69         {
       
    70         AppUi()->RemoveFromViewStack(*this, iContainer);
       
    71         delete iContainer;
       
    72         }
       
    73     delete iIdle;
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CUserDictView::SaveL
       
    78 // Saves the changes of the element and updates ListBox.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CUserDictView::SaveL(
       
    82     const TUDictElement& aNewItem, const TUDictElement& aOldItem) const
       
    83     {
       
    84 #if defined(_DEBUG)
       
    85     __ASSERT_DEBUG(!aNewItem.IsEmpty(),
       
    86         User::Panic(KPanicCatView, KErrCorrupt));
       
    87 #endif
       
    88     TInt index(iContainer ? iContainer->ListBox()->CurrentItemIndex() : 0);
       
    89     if (aOldItem.IsEmpty())
       
    90         {
       
    91         index = iModel.AddNewWordL(aNewItem);
       
    92         }
       
    93     else
       
    94         {
       
    95         index = iModel.ModifyWordL(index, aNewItem);
       
    96         }
       
    97 
       
    98 #ifdef RD_PF_SEC_APPARC
       
    99     if (iEmbedded)
       
   100 #else
       
   101     if (AppUi()->ContainerAppUi())
       
   102 #endif
       
   103         {
       
   104         iModel.SetChangeNotice(ETrue);
       
   105         }
       
   106 
       
   107     if (iContainer)
       
   108         {
       
   109         iContainer->SetFocusL(index);
       
   110         }
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CUserDictView::ShowInformationNoteL
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CUserDictView::ShowInformationNoteL(TInt aResourceId) const
       
   118     {
       
   119     TBuf<KMessageBuffSize> message;
       
   120     iCoeEnv->ReadResource(message, aResourceId);
       
   121     CAknInformationNote* note = new(ELeave) CAknInformationNote();
       
   122     note->ExecuteLD(message);
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CUserDictView::CUserDictView
       
   127 // C++ default constructor can NOT contain any code, that
       
   128 // might leave.
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 CUserDictView::CUserDictView(CUserDictModel& aModel)
       
   132 :iModel(aModel)
       
   133     {
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CUserDictView::ConstructL
       
   138 // Symbian 2nd phase constructor can leave.
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CUserDictView::ConstructL()
       
   142     {
       
   143     BaseConstructL(R_UDICT_VIEW);
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CUserDictView::ShowDeleteConfQueryL
       
   148 // Shows delete confirmation query.
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 TInt CUserDictView::ShowDeleteConfQueryL(TInt aCount) const
       
   152     {
       
   153     TInt ret(0);
       
   154     if (aCount <= 1)
       
   155         {
       
   156         CAknQueryDialog* dialog = CAknQueryDialog::NewL();
       
   157         ret = dialog->ExecuteLD(R_UDICT_DELETE_QUERY);
       
   158         }
       
   159     else
       
   160         {
       
   161         HBufC* message = StringLoader::LoadL(
       
   162             R_UDICT_DELETE_QUERY_MESSAGE, aCount, iCoeEnv);
       
   163         CleanupStack::PushL(message);
       
   164         CAknQueryDialog* dialog = CAknQueryDialog::NewL();
       
   165         ret = dialog->ExecuteLD(R_UDICT_DELETE_QUERY, *message);
       
   166         CleanupStack::PopAndDestroy(); // message
       
   167         }
       
   168     return ret;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CUserDictView::ShowEditorFormL
       
   173 // Shows user dictionary editor form.
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CUserDictView::ShowEditorFormL(const TUDictElement& item)
       
   177     {
       
   178     CUserDictForm* form = CUserDictForm::NewL(item, *this);
       
   179     form->ExecuteLD(R_UDICT_DIALOG_EDIT);
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CUserDictView::UpdateListL
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 void CUserDictView::UpdateListL()
       
   187     {
       
   188     iModel.InitListL();
       
   189     TInt index(iContainer->ListBox()->CurrentItemIndex());
       
   190     iContainer->SetFocusL(
       
   191         (iModel.List()->MdcaCount() > 0 && index < 0) ? 0 : index);
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CUserDictView::RegisterByAnotherApp
       
   196 // iIdle's call back function
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 TInt CUserDictView::RegisterByAnotherApp(TAny* aView)
       
   200     {
       
   201     static_cast<CUserDictView*>(aView)->DoRegisterByAnotherApp();
       
   202     return 0;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CUserDictView::DoRegisterByAnotherApp
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 void CUserDictView::DoRegisterByAnotherApp()
       
   210     {
       
   211     iIdle->Cancel();
       
   212 
       
   213     // If HandleCommandL() leaves, this application can't exit.
       
   214     // So, it needs to be trapped.
       
   215     TRAP_IGNORE(HandleCommandL(EUserDictCmdNewWord));
       
   216 
       
   217 #ifdef RD_PF_SEC_APPARC
       
   218     // In case RD_PF_SEC_APPARC, CEikAppui::Exit()
       
   219     // CEikAppui::Exit() always leave :Leave code = KLeaveExit(-1003)
       
   220     // KLeaveExit should be not trapped. So Exit() is called directly.
       
   221     AppUi()->Exit();
       
   222 #else
       
   223     // CEikAppui::Exit() must leave, at that time,
       
   224     // this iIdle has deleted already.
       
   225     // So, it needs to be trapped.
       
   226     TRAP_IGNORE(AppUi()->HandleCommandL(EEikCmdExit));
       
   227 #endif
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // TUid CUserDictView::Id
       
   232 // From CAknView
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 TUid CUserDictView::Id() const
       
   236     {
       
   237     return KViewId;
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CUserDictView::HandleCommandL
       
   242 // From CAknView
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CUserDictView::HandleCommandL(TInt aCommand)
       
   246     {
       
   247     switch (aCommand)
       
   248         {
       
   249         case EAknSoftkeyExit:
       
   250             AppUi()->HandleCommandL(EEikCmdExit);
       
   251             break;
       
   252         case EUserDictCmdOpen:
       
   253             {
       
   254             if (iModel.List()->MdcaCount() <= 0
       
   255                 || iContainer->ListBox()->View()->SelectionIndexes()->Count() > 0)
       
   256                 {
       
   257                 // It shows context sensitive menu.
       
   258                 CEikMenuBar* menuBar = MenuBar();
       
   259                 menuBar->SetMenuTitleResourceId(
       
   260                             R_UDICT_MENUBAR_VIEW_CONTEXT);
       
   261                 menuBar->TryDisplayMenuBarL();
       
   262                 menuBar->SetMenuTitleResourceId(
       
   263                             R_UDICT_MENUBAR_VIEW);
       
   264                 }
       
   265             else
       
   266                 {
       
   267                 TUDictElement item(iModel.ListItem(
       
   268                         iContainer->ListBox()->CurrentItemIndex()));
       
   269                 ShowEditorFormL(item);
       
   270                 // Show correct softkey
       
   271                 ShowSoftkeyL();
       
   272                 }
       
   273             }
       
   274             break;
       
   275         case EUserDictCmdNewWord:
       
   276             if (!iModel.IsDictionaryFull())
       
   277                 {
       
   278                 TUDictElement item;
       
   279                 ShowEditorFormL(item);
       
   280                 // Show correct softkey
       
   281                 ShowSoftkeyL();
       
   282                 }
       
   283             else
       
   284                 {
       
   285                 ShowInformationNoteL(R_UDICT_INFO_MEMORY_FULL_MESSAGE);
       
   286                 }
       
   287             break;
       
   288         case EUserDictCmdDelete:
       
   289              // Forbids the list update in HandleForegroundL while deleting.
       
   290             iLockListUpdate = ETrue;
       
   291             if (ShowDeleteConfQueryL(
       
   292                 iContainer->ListBox()->View()->SelectionIndexes()->Count()))
       
   293                 {
       
   294                 iContainer->DeleteItemL();
       
   295                 }
       
   296             iLockListUpdate = EFalse;
       
   297             if (iModel.IsChangedByAnotherApp())
       
   298                 {
       
   299                 UpdateListL();
       
   300                 }
       
   301             // Show correct softkey
       
   302             ShowSoftkeyL();
       
   303             break;
       
   304         case EAknCmdHelp:
       
   305             HlpLauncher::LaunchHelpApplicationL(
       
   306                 iCoeEnv->WsSession(), AppUi()->AppHelpContextL());
       
   307             break;
       
   308         default:
       
   309 		    if (iContainer && iModel.List()->MdcaCount() > 0)
       
   310 		        {
       
   311 				TInt previous = iContainer->ListBox()->View()->SelectionIndexes()->Count();
       
   312 		        AknSelectionService::HandleMarkableListProcessCommandL(
       
   313 		                                aCommand, iContainer->ListBox());
       
   314 				if (previous != iContainer->ListBox()->View()->SelectionIndexes()->Count())
       
   315 					{
       
   316 		            // Show correct softkey
       
   317 		            ShowSoftkeyL();
       
   318 					}
       
   319 		        }
       
   320             AppUi()->HandleCommandL(aCommand);
       
   321             break;
       
   322         }
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CUserDictView::HandleClientRectChange
       
   327 // From CAknView
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 void CUserDictView::HandleClientRectChange()
       
   331     {
       
   332     if (iContainer)
       
   333         {
       
   334         iContainer->SetRect(ClientRect());
       
   335         }
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CUserDictView::DoActivateL
       
   340 // From CAknView
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 void CUserDictView::DoActivateL(
       
   344    const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
       
   345    const TDesC8& /*aCustomMessage*/)
       
   346     {
       
   347 #ifdef RD_PF_SEC_APPARC
       
   348 
       
   349     iEmbedded = EFalse;
       
   350 
       
   351     RArray<RWsSession::TWindowGroupChainInfo> wgs;
       
   352     CleanupClosePushL( wgs );
       
   353     TInt err = iEikonEnv->WsSession().WindowGroupList(&wgs);
       
   354     if (err == KErrNone)
       
   355         {
       
   356         TInt wgId = iEikonEnv->RootWin().Identifier();
       
   357         TInt count = wgs.Count();
       
   358         for (TInt ii=0; ii < count; ii++)
       
   359             {
       
   360             const RWsSession::TWindowGroupChainInfo& info = wgs[ii];
       
   361             // find the window group id and check that it has no parent
       
   362             if (info.iId == wgId)
       
   363                 {
       
   364                 if (info.iParentId > 0)
       
   365                     {
       
   366                     iEmbedded = ETrue;
       
   367                     }
       
   368                 break;
       
   369                 }
       
   370             }
       
   371         }
       
   372     wgs.Reset();
       
   373     CleanupStack::PopAndDestroy( &wgs );
       
   374 
       
   375     if (!iEmbedded)
       
   376         {
       
   377         // I'm standalone application
       
   378         iContainer = new(ELeave) CUserDictContainer(iModel, *this);
       
   379         iContainer->SetMopParent(this);
       
   380         iContainer->ConstructL();
       
   381         iContainer->SetRect(ClientRect());
       
   382         iContainer->ActivateL();
       
   383 
       
   384         AppUi()->AddToStackL(*this, iContainer);
       
   385         // Set context menu
       
   386         MenuBar()->SetContextMenuTitleResourceId
       
   387             ( R_UDICT_MENUBAR_VIEW_CONTEXT );
       
   388         }
       
   389     else
       
   390         {
       
   391         // embedded using window group chaining
       
   392         iIdle = CIdle::NewL(CActive::EPriorityIdle);
       
   393         // It calls CUserDictView::RegisterByAnotherApp()
       
   394         // after the activation of View finishes.
       
   395         iIdle->Start(TCallBack(RegisterByAnotherApp, this));
       
   396         }
       
   397 
       
   398 #else
       
   399 
       
   400     if (AppUi()->ContainerAppUi()) // started up by another application.
       
   401         {
       
   402         iIdle = CIdle::NewL(CActive::EPriorityIdle);
       
   403         // It calls CUserDictView::RegisterByAnotherApp()
       
   404         // after the activation of View finishes.
       
   405         iIdle->Start(TCallBack(RegisterByAnotherApp, this));
       
   406         }
       
   407     else if (!iContainer)
       
   408         {
       
   409         iContainer = new(ELeave) CUserDictContainer(iModel, *this);
       
   410         iContainer->SetMopParent(this);
       
   411         iContainer->ConstructL();
       
   412         iContainer->SetRect(ClientRect());
       
   413         iContainer->ActivateL();
       
   414 
       
   415         AppUi()->AddToStackL(*this, iContainer);
       
   416         }
       
   417 #endif //RD_PF_SEC_APPARC
       
   418 
       
   419    }
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 // CUserDictView::DoDeactivate
       
   423 // From CAknView
       
   424 // -----------------------------------------------------------------------------
       
   425 //
       
   426 void CUserDictView::DoDeactivate()
       
   427     {
       
   428     if (iContainer)
       
   429         {
       
   430         AppUi()->RemoveFromViewStack(*this, iContainer);
       
   431         delete iContainer;
       
   432         iContainer = NULL;
       
   433         }
       
   434     }
       
   435 
       
   436 // -----------------------------------------------------------------------------
       
   437 // CUserDictView::HandleForegroundEventL
       
   438 // From CAknView
       
   439 // -----------------------------------------------------------------------------
       
   440 //
       
   441 void CUserDictView::HandleForegroundEventL(TBool aForeground)
       
   442     {
       
   443     CAknView::HandleForegroundEventL(aForeground);
       
   444 
       
   445     if (aForeground)
       
   446         {
       
   447         iModel.ReloadDictInfoL();
       
   448 
       
   449 #ifdef RD_PF_SEC_APPARC
       
   450         if (!iEmbedded
       
   451             && iModel.IsChangedByAnotherApp()
       
   452             && !iLockListUpdate)
       
   453 #else
       
   454         if (!AppUi()->ContainerAppUi()
       
   455             && iModel.IsChangedByAnotherApp()
       
   456             && !iLockListUpdate)
       
   457 #endif
       
   458             {
       
   459             // When the User dictionary data has been changed while the
       
   460             // application was running on background, it updates the ListBox.
       
   461             UpdateListL();
       
   462             }
       
   463         // Show correct softkey
       
   464         ShowSoftkeyL();
       
   465         }
       
   466     else if (iContainer && iContainer->IsFocused())
       
   467         {
       
   468         iLockListUpdate = EFalse;
       
   469         }
       
   470     }
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // CUserDictView::DynInitMenuPaneL
       
   474 // From MEikMenuObserver
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 void CUserDictView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane *aMenu)
       
   478     {
       
   479     CAknView::DynInitMenuPaneL(aResourceId, aMenu);
       
   480     if (iContainer)
       
   481         {
       
   482         AknSelectionService::HandleMarkableListDynInitMenuPane(
       
   483                     aResourceId, aMenu, iContainer->ListBox());
       
   484         }
       
   485     if (aResourceId == R_UDICT_APP_MENU)
       
   486         {
       
   487         if (iModel.List()->MdcaCount() == 0)
       
   488             {
       
   489             aMenu->DeleteMenuItem(EUserDictCmdOpen);
       
   490             aMenu->DeleteMenuItem(EUserDictCmdDelete);
       
   491             }
       
   492         if (!FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   493             {
       
   494             aMenu->DeleteMenuItem(EAknCmdHelp);
       
   495             }
       
   496         }
       
   497     else if (aResourceId == R_UDICT_APP_MENU_CONTEXT)
       
   498         {
       
   499         if (iModel.List()->MdcaCount() == 0)
       
   500             {
       
   501             aMenu->DeleteMenuItem(EUserDictCmdDelete);
       
   502             }
       
   503         else
       
   504             {
       
   505             aMenu->DeleteMenuItem(EUserDictCmdNewWord);
       
   506             }
       
   507         }
       
   508     }
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // CUserDictView::ShowSoftkeyL
       
   512 // Show softkeys
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 void CUserDictView::ShowSoftkeyL()
       
   516     {
       
   517 #ifdef RD_PF_SEC_APPARC
       
   518     if (iEmbedded)
       
   519 #else
       
   520     if (AppUi()->ContainerAppUi())
       
   521 #endif
       
   522         {
       
   523         Cba()->SetCommandSetL(R_UDICT_VIEW_CBA_SOFTKEY_EMPTY);
       
   524         }
       
   525     else
       
   526         {
       
   527         if (iModel.List()->MdcaCount() > 0)
       
   528             {
       
   529             if (iContainer->ListBox()->View()->SelectionIndexes()->Count() > 0)
       
   530                 {
       
   531                 // There is(are) the selected item(s)
       
   532                 Cba()->SetCommandSetL(R_UDICT_VIEW_CBA_SOFTKEY_CONTEXTOPTIONS);
       
   533                 }
       
   534             else
       
   535                 {
       
   536                 // There is no the selected item(s)
       
   537                 Cba()->SetCommandSetL(R_UDICT_VIEW_CBA_SOFTKEY_OPEN);
       
   538                 }
       
   539             }
       
   540         else
       
   541             {
       
   542             Cba()->SetCommandSetL(R_UDICT_VIEW_CBA_SOFTKEY_NEWWORD);
       
   543             }
       
   544         }
       
   545     Cba()->DrawNow();
       
   546     }
       
   547 
       
   548 //  End of File