notepad/notepad1/LibSrc/NpdPopupList.cpp
branchRCL_3
changeset 66 bd7edf625bdd
child 67 1539a383d7b6
equal deleted inserted replaced
65:12af337248b1 66:bd7edf625bdd
       
     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:  Implementation of Fetch memos/templates Popup List.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknPopup.h>
       
    21 #include <aknenv.h>
       
    22 #include <eikappui.h>
       
    23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    24 #include <vwsdefpartner.h>
       
    25 #endif
       
    26 
       
    27 #include "NpdPopupList.h"
       
    28 #include "NpdModel_platsec.h"
       
    29 #include "NpdModelObserver.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CNotepadPopupList::NewL
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CNotepadPopupList* CNotepadPopupList::NewL(
       
    38     CEikListBox* aListBox, 
       
    39     TInt aCbaResource, 
       
    40     AknPopupLayouts::TAknPopupLayouts aType,
       
    41     CNotepadModel& aModel )
       
    42     {
       
    43     CNotepadPopupList* self = 
       
    44         new(ELeave) CNotepadPopupList( aModel );
       
    45     CleanupStack::PushL(self);
       
    46     self->ConstructL(aListBox, aCbaResource, aType);
       
    47     CleanupStack::Pop();
       
    48     return self;
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CNotepadPopupList::CNotepadPopupList
       
    53 // C++ constructor
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CNotepadPopupList::CNotepadPopupList(
       
    57     CNotepadModel& aModel )
       
    58     :CAknPopupList(), iModel(aModel)
       
    59     {
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CNotepadPopupList::~CNotepadPopupList
       
    64 // destructor
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CNotepadPopupList::~CNotepadPopupList()
       
    68     {
       
    69     if ( iFlags & ENotepadObserveView )
       
    70         {
       
    71         iEikonEnv->EikAppUi()->RemoveViewObserver(this);
       
    72         }
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CNotepadPopupList::EnhancedExecuteLD
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 TBool CNotepadPopupList::EnhancedExecuteLD( TBool& aFinished )
       
    80     {
       
    81     iEikonEnv->EikAppUi()->AddViewObserverL(this);
       
    82     iFlags |= ENotepadObserveView;
       
    83     TBool returnValue(EFalse);
       
    84     aFinished = ETrue;
       
    85     iFinished = &aFinished;
       
    86     
       
    87     TInt count( iModel.MdcaCount() );
       
    88     
       
    89     if(0 == count )
       
    90         {
       
    91           ButtonGroupContainer()->SetCommandSetL( R_AVKON_SOFTKEYS_CANCEL );  
       
    92           ButtonGroupContainer()->DrawNow();
       
    93         }
       
    94     else 
       
    95     	{
       
    96     	  ButtonGroupContainer()->SetCommandSetL(R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT);
       
    97     	  ButtonGroupContainer()->DrawNow();
       
    98     	}
       
    99     
       
   100     iReturn = NULL; // to avoid a problem of CAknPopupList::ExecuteLD
       
   101 
       
   102     returnValue = ExecuteLD();
       
   103 
       
   104     // iFinished should be cleared ('finished' goes out of its extent)
       
   105      iFinished = NULL; 
       
   106     
       
   107     return returnValue;
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CNotepadPopupList::AttemptExitL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CNotepadPopupList::AttemptExitL(TBool aAccept)
       
   115     {
       
   116     if ( !iFinished || *iFinished ) // really finished
       
   117         {
       
   118         CAknPopupList::AttemptExitL(aAccept);
       
   119         if ( iFlags & ENotepadIsViewDeactivated )
       
   120         	{
       
   121             iEikonEnv->RemoveFromStack(this);
       
   122             CAknEnv::StopSchedulerWaitWithBusyMessage(iWait);	
       
   123         	}        
       
   124         }
       
   125     else // empty -> non-empty
       
   126         {
       
   127         iEikonEnv->RemoveFromStack(this);
       
   128         CAknEnv::StopSchedulerWaitWithBusyMessage(iWait);
       
   129         }
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CNotepadPopupList::HandleNotepadModelEventL
       
   134 //
       
   135 // [1]
       
   136 // There was a problem in the following sequence;
       
   137 //   1. Popup our list with some memos using NpdTest.app,
       
   138 //   2. Task switch to Notepad and remove all memos,
       
   139 //   3. Task switch to NpdTest.app ( empty popup list ),
       
   140 //   4. Task switch to Notepad again and add 3 memos,
       
   141 //   5. Task switch to NpdTest.app again,
       
   142 //   then, the popup list contains 3 memos but the boundary rectangle was
       
   143 //   corrupted.
       
   144 // In order to solve this problem, we add
       
   145 //    SetupWindowLayout( AknPopupLayouts::EMenuWindow ); // [1]
       
   146 // in this function.
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CNotepadPopupList::HandleNotepadModelEventL(
       
   150     TEvent aEvent, 
       
   151     TInt /*aParam*/ )
       
   152     {
       
   153     switch ( aEvent )
       
   154         {
       
   155         case EDatabaseChanged:
       
   156             if ( !(iFlags & ENotepadIsViewDeactivated) )
       
   157                 {
       
   158                 iModel.SyncL(EFalse);
       
   159                 }
       
   160             break;
       
   161         case EStartItemArrayChange:
       
   162             iSavedCount = iModel.MdcaCount();
       
   163             iSavedIndex = ListBox()->CurrentItemIndex();
       
   164             break;
       
   165         case ECompleteItemArrayChange:
       
   166             {
       
   167             TInt count( iModel.MdcaCount() );
       
   168             if ( iFinished &&
       
   169                 ( iSavedCount > 0 ? count == 0 : count > 0 ) )
       
   170                 {
       
   171                 if ( iSavedCount == 0 ) // empty -> not empty
       
   172                     {
       
   173                     *iFinished = EFalse;
       
   174                     MakeVisible(ETrue);
       
   175                     TKeyEvent key;
       
   176                     key.iCode=EKeyEscape;
       
   177                     key.iModifiers=0;
       
   178                     iCoeEnv->SimulateKeyEventL(key, EEventKey);
       
   179                     SetupWindowLayout( AknPopupLayouts::EMenuWindow ); // [1]
       
   180                     ButtonGroupContainer()->SetCommandSetL(R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT);  
       
   181                     ButtonGroupContainer()->DrawNow();
       
   182                                      
       
   183                     iEikonEnv->AddSleepingDialogToStackL( this );
       
   184                     }
       
   185                 else // not empty -> empty
       
   186                     {
       
   187                     ListBox()->Reset();
       
   188                     //ListBox()->HandleItemRemovalL();
       
   189                     *iFinished = EFalse;
       
   190                     iEikonEnv->RemoveFromStack(this);
       
   191                     CAknEnv::StopSchedulerWaitWithBusyMessage(iWait);
       
   192                     ButtonGroupContainer()->SetCommandSetL(R_AVKON_SOFTKEYS_CANCEL);  
       
   193                     ButtonGroupContainer()->DrawNow();
       
   194                     SetFocus(EFalse);                    
       
   195                     }
       
   196                 }
       
   197             else 
       
   198                 {
       
   199                 if ( count > 0 && iSavedIndex >= count ) // reduced
       
   200                     {
       
   201                     ListBox()->SetCurrentItemIndex( count - 1 );
       
   202                     }
       
   203                 ListBox()->HandleItemRemovalL();
       
   204                 ListBox()->ScrollBarFrame()->MoveVertThumbTo(
       
   205                     ListBox()->CurrentItemIndex() );
       
   206                 SetupWindowLayout( AknPopupLayouts::EMenuWindow );
       
   207                 DrawNow();
       
   208                 }
       
   209             }
       
   210             break;
       
   211         default:
       
   212             break;
       
   213         }
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CNotepadPopupList::HandleViewEventL
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void CNotepadPopupList::HandleViewEventL(const TVwsViewEvent& aEvent)
       
   221     {
       
   222     switch ( aEvent.iEventType )
       
   223         {
       
   224         case TVwsViewEvent::EVwsActivateView:
       
   225             {
       
   226             iFlags &= ~ENotepadIsViewDeactivated;
       
   227             TRAPD(err, iModel.SyncL(EFalse));
       
   228             if (err != KErrNone)
       
   229                 {
       
   230                 iCoeEnv->HandleError(err);
       
   231                 CAknPopupList::AttemptExitL(EFalse);
       
   232                 }
       
   233             }
       
   234             break;
       
   235         case TVwsViewEvent::EVwsDeactivateView:
       
   236             iFlags |= ENotepadIsViewDeactivated;
       
   237             break;
       
   238         default:
       
   239             break;
       
   240         }
       
   241     }
       
   242 
       
   243 // End of File