notepad/notepad1/LibSrc/NpdPopupList.cpp
changeset 0 f979ecb2b13e
child 11 0f07cd1b5772
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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         }
       
   120     else // empty -> non-empty
       
   121         {
       
   122         iEikonEnv->RemoveFromStack(this);
       
   123         CAknEnv::StopSchedulerWaitWithBusyMessage(iWait);
       
   124         }
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CNotepadPopupList::HandleNotepadModelEventL
       
   129 //
       
   130 // [1]
       
   131 // There was a problem in the following sequence;
       
   132 //   1. Popup our list with some memos using NpdTest.app,
       
   133 //   2. Task switch to Notepad and remove all memos,
       
   134 //   3. Task switch to NpdTest.app ( empty popup list ),
       
   135 //   4. Task switch to Notepad again and add 3 memos,
       
   136 //   5. Task switch to NpdTest.app again,
       
   137 //   then, the popup list contains 3 memos but the boundary rectangle was
       
   138 //   corrupted.
       
   139 // In order to solve this problem, we add
       
   140 //    SetupWindowLayout( AknPopupLayouts::EMenuWindow ); // [1]
       
   141 // in this function.
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CNotepadPopupList::HandleNotepadModelEventL(
       
   145     TEvent aEvent, 
       
   146     TInt /*aParam*/ )
       
   147     {
       
   148     switch ( aEvent )
       
   149         {
       
   150         case EDatabaseChanged:
       
   151             if ( !(iFlags & ENotepadIsViewDeactivated) )
       
   152                 {
       
   153                 iModel.SyncL(EFalse);
       
   154                 }
       
   155             break;
       
   156         case EStartItemArrayChange:
       
   157             iSavedCount = iModel.MdcaCount();
       
   158             iSavedIndex = ListBox()->CurrentItemIndex();
       
   159             break;
       
   160         case ECompleteItemArrayChange:
       
   161             {
       
   162             TInt count( iModel.MdcaCount() );
       
   163             if ( iFinished &&
       
   164                 ( iSavedCount > 0 ? count == 0 : count > 0 ) )
       
   165                 {
       
   166                 if ( iSavedCount == 0 ) // empty -> not empty
       
   167                     {
       
   168                     *iFinished = EFalse;
       
   169                     MakeVisible(ETrue);
       
   170                     TKeyEvent key;
       
   171                     key.iCode=EKeyEscape;
       
   172                     key.iModifiers=0;
       
   173                     iCoeEnv->SimulateKeyEventL(key, EEventKey);
       
   174                     SetupWindowLayout( AknPopupLayouts::EMenuWindow ); // [1]
       
   175                     ButtonGroupContainer()->SetCommandSetL(R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT);  
       
   176                     ButtonGroupContainer()->DrawNow();
       
   177                                      
       
   178                     iEikonEnv->AddSleepingDialogToStackL( this );
       
   179                     }
       
   180                 else // not empty -> empty
       
   181                     {
       
   182                     ListBox()->Reset();
       
   183                     //ListBox()->HandleItemRemovalL();
       
   184                     *iFinished = EFalse;
       
   185                     iEikonEnv->RemoveFromStack(this);
       
   186                     CAknEnv::StopSchedulerWaitWithBusyMessage(iWait);
       
   187                     ButtonGroupContainer()->SetCommandSetL(R_AVKON_SOFTKEYS_CANCEL);  
       
   188                     ButtonGroupContainer()->DrawNow();
       
   189                     SetFocus(EFalse);                    
       
   190                     }
       
   191                 }
       
   192             else 
       
   193                 {
       
   194                 if ( count > 0 && iSavedIndex >= count ) // reduced
       
   195                     {
       
   196                     ListBox()->SetCurrentItemIndex( count - 1 );
       
   197                     }
       
   198                 ListBox()->HandleItemRemovalL();
       
   199                 ListBox()->ScrollBarFrame()->MoveVertThumbTo(
       
   200                     ListBox()->CurrentItemIndex() );
       
   201                 SetupWindowLayout( AknPopupLayouts::EMenuWindow );
       
   202                 DrawNow();
       
   203                 }
       
   204             }
       
   205             break;
       
   206         default:
       
   207             break;
       
   208         }
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CNotepadPopupList::HandleViewEventL
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CNotepadPopupList::HandleViewEventL(const TVwsViewEvent& aEvent)
       
   216     {
       
   217     switch ( aEvent.iEventType )
       
   218         {
       
   219         case TVwsViewEvent::EVwsActivateView:
       
   220             {
       
   221             iFlags &= ~ENotepadIsViewDeactivated;
       
   222             TRAPD(err, iModel.SyncL(EFalse));
       
   223             if (err != KErrNone)
       
   224                 {
       
   225                 iCoeEnv->HandleError(err);
       
   226                 CAknPopupList::AttemptExitL(EFalse);
       
   227                 }
       
   228             }
       
   229             break;
       
   230         case TVwsViewEvent::EVwsDeactivateView:
       
   231             iFlags |= ENotepadIsViewDeactivated;
       
   232             break;
       
   233         default:
       
   234             break;
       
   235         }
       
   236     }
       
   237 
       
   238 // End of File