javamanager/javasettings/appmngrplugin/src/appmngr2midletsettingscontainer.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2003-2008 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:  CAppMngr2MidletSettingsContainer implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknlists.h>                           // CAknSettingStyleListBox
       
    21 #include "javaapplicationsettings.hlp.hrh"
       
    22 
       
    23 #include "appmngr2midletsettingscontainer.h"    // CAppMngr2MidletSettingsContainer
       
    24 #include "appmngr2midletsettingsview.h"         // CAppMngr2MidletSettingsView
       
    25 #include "javaapplicationsettings.hrh"                   // Midlet command IDs
       
    26 
       
    27 #include "logger.h"                          // LOG
       
    28 
       
    29 // LOCAL CONSTANTS AND MACROS
       
    30 // UID of the application
       
    31 const TUid KOwnUid = { 0x20016BF7 };  // Own Uid, used with help
       
    32 
       
    33 using namespace std;
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // C++ constructor
       
    39 // ---------------------------------------------------------------------------
       
    40 CAppMngr2MidletSettingsContainer::CAppMngr2MidletSettingsContainer(
       
    41     CAppMngr2MidletSettingsView& aView) : iView(aView), iListbox(NULL)
       
    42 {
       
    43     LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletSettingsContainer::CAppMngr2MidletSettingsContainer");
       
    44     iListBoxContent.clear();
       
    45 }
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CAppMngr2MidletSettingsContainer::ConstructL(const TRect& aRect)
       
    49 // Symbian OS two phased constructor
       
    50 // Creates new window and listbox
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 void CAppMngr2MidletSettingsContainer::ConstructL(const TRect& aRect)
       
    54 {
       
    55     LOG(EJavaAppMngrPlugin, EInfo, " + CAppMngr2MidletSettingsContainer::ConstructL ");
       
    56     CreateWindowL();
       
    57 
       
    58     iListbox = new(ELeave) CAknSettingStyleListBox;
       
    59 
       
    60     iListbox->SetContainerWindowL(*this);
       
    61     iListbox->ConstructL(this,EAknListBoxSelectionList | EAknListBoxItemSpecificMenuDisabled);
       
    62 
       
    63     // set up the listbox
       
    64     iListbox->CreateScrollBarFrameL(ETrue);
       
    65     iListbox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn,
       
    66             CEikScrollBarFrame::EAuto);
       
    67 
       
    68     iListbox->SetRect(aRect.Size());
       
    69     iListbox->ActivateL();
       
    70 
       
    71     SetRect(aRect);
       
    72     ActivateL();
       
    73 
       
    74     iListbox->SetCurrentItemIndex(0);
       
    75 
       
    76     LOG(EJavaAppMngrPlugin, EInfo, " - CAppMngr2MidletSettingsContainer::ConstructL ");
       
    77 }
       
    78 
       
    79 // Destructor
       
    80 CAppMngr2MidletSettingsContainer::~CAppMngr2MidletSettingsContainer()
       
    81 {
       
    82     LOG(EJavaAppMngrPlugin, EInfo, " + CAppMngr2MidletSettingsContainer::~CAppMngr2MidletSettingsContainer ");
       
    83     if (iListbox)
       
    84     {
       
    85         iListbox->Reset();
       
    86         delete iListbox;
       
    87     }
       
    88     iListBoxContent.clear();
       
    89     LOG(EJavaAppMngrPlugin, EInfo, " - CAppMngr2MidletSettingsContainer::~CAppMngr2MidletSettingsContainer ");
       
    90 }
       
    91 
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 //  CAppMngr2MidletSettingsContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
    95 //  This handles the scrolling the list by arrows and the clear key and OK key
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 TKeyResponse CAppMngr2MidletSettingsContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
    99         TEventCode aType)
       
   100 {
       
   101     LOG(EJavaAppMngrPlugin, EInfo, " + CAppMngr2MidletSettingsContainer::OfferKeyEventL ");
       
   102     TKeyResponse retval = EKeyWasNotConsumed;
       
   103 
       
   104     switch (aKeyEvent.iCode)
       
   105     {
       
   106     case EKeyOK:
       
   107         // This key event is handeled by main view as a command.
       
   108         iView.HandleCommandL(EAknSoftkeyChange);
       
   109         break;
       
   110 
       
   111     case EKeyUpArrow:   // fallthrough
       
   112     case EKeyDownArrow:
       
   113     default:
       
   114         retval = iListbox->OfferKeyEventL(aKeyEvent, aType);
       
   115         break;
       
   116     }
       
   117 
       
   118     LOG(EJavaAppMngrPlugin, EInfo, " - CAppMngr2MidletSettingsContainer::OfferKeyEventL ");
       
   119     return retval;
       
   120 }
       
   121 
       
   122 
       
   123 // ---------------------------------------------------------
       
   124 // CAppMngr2MidletSettingsContainer::SizeChanged()
       
   125 // Called by framework when the view size is changed
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 void CAppMngr2MidletSettingsContainer::SizeChanged()
       
   129 {
       
   130     LOG(EJavaAppMngrPlugin, EInfo, " CAppMngr2MidletSettingsContainer::SizeChanged ");
       
   131     iListbox->SetRect(Rect());
       
   132 }
       
   133 
       
   134 // ---------------------------------------------------------
       
   135 // CAppMngr2MidletSettingsContainer::CountComponentControls() const
       
   136 // ---------------------------------------------------------
       
   137 //
       
   138 TInt CAppMngr2MidletSettingsContainer::CountComponentControls() const
       
   139 {
       
   140     LOG(EJavaAppMngrPlugin, EInfo, " CAppMngr2MidletSettingsContainer::CountComponentControls ");
       
   141     return iListbox ? 1 : 0;
       
   142 }
       
   143 
       
   144 // ---------------------------------------------------------
       
   145 // CAppMngr2MidletSettingsContainer::ComponentControl(TInt aIndex) const
       
   146 // ---------------------------------------------------------
       
   147 //
       
   148 CCoeControl* CAppMngr2MidletSettingsContainer::ComponentControl(TInt aIndex) const
       
   149 {
       
   150     LOG(EJavaAppMngrPlugin, EInfo, " CAppMngr2MidletSettingsContainer::ComponentControl ");
       
   151     switch (aIndex)
       
   152     {
       
   153     case 0:
       
   154         return iListbox;
       
   155     default:
       
   156         return NULL;
       
   157     }
       
   158 }
       
   159 
       
   160 void CAppMngr2MidletSettingsContainer::RefreshListBoxContentL(int aListBoxContentIndex, int aSelectedItemIndex, bool aAllEnabled)
       
   161 {
       
   162     // refresh the rest
       
   163     TInt lastListBoxPos = iListbox->CurrentItemIndex();
       
   164     TInt lastListBoxTopPos = iListbox->TopItemIndex();
       
   165 
       
   166     // refresh the current item
       
   167     RefreshListBoxContentL(aListBoxContentIndex, aSelectedItemIndex);
       
   168 
       
   169     MDesCArray* itemList = iListbox->Model()->ItemTextArray();
       
   170     CDesCArray* itemArray = static_cast<CDesCArray*>(itemList);
       
   171 
       
   172     HBufC* itemValue = HBufC::NewLC(KMaxDataTypeLength);
       
   173     TPtr itemPtr = itemValue->Des();
       
   174 
       
   175     for (int i=(aListBoxContentIndex+1); i<iListBoxContent.size(); i++)
       
   176     {
       
   177         bool wasEnabled = iListBoxContent[i].getEnabled();
       
   178         iListBoxContent[i].setEnabled(aAllEnabled);
       
   179         if (aAllEnabled)
       
   180         {
       
   181             if (wasEnabled)
       
   182             {
       
   183                 continue;
       
   184             }
       
   185             // add it to the list
       
   186             // add name
       
   187             itemPtr.Zero();
       
   188             itemPtr += _L("\t");
       
   189             wstring name = iListBoxContent[i].getName().getValue();
       
   190             TPtr ptr((unsigned short*)name.c_str(), name.size());
       
   191             ptr.SetLength(name.size());
       
   192             itemPtr += AknTextUtils::ChooseScalableText(ptr,*iCoeEnv->NormalFont(), NULL);
       
   193             itemPtr += _L("\t");
       
   194             itemPtr += _L("\t");
       
   195             // add value
       
   196             wstring value = iListBoxContent[i].getValue().getValue();
       
   197             ptr.Set((unsigned short*)value.c_str(), value.size(), value.size());
       
   198             ptr.SetLength(value.size());
       
   199             itemPtr += AknTextUtils::ChooseScalableText(ptr,*iCoeEnv->NormalFont(), NULL);
       
   200             itemArray->AppendL(itemPtr);
       
   201         }
       
   202         else
       
   203         {
       
   204             itemArray->Delete(lastListBoxPos + 1);
       
   205         }
       
   206     }
       
   207 
       
   208     CleanupStack::PopAndDestroy(itemValue);
       
   209 
       
   210     // Handle content changes
       
   211     iListbox->Reset();
       
   212     // set indexes
       
   213     if (lastListBoxPos != -1)
       
   214     {
       
   215         iListbox->SetCurrentItemIndex(lastListBoxPos);
       
   216         iListbox->SetTopItemIndex(lastListBoxTopPos);
       
   217     }
       
   218     // Draw it
       
   219     iListbox->DrawDeferred();
       
   220 }
       
   221 void CAppMngr2MidletSettingsContainer::RefreshListBoxContentL(int aListBoxContentIndex, int aSelectedItemIndex, const ListItem& aListItem)
       
   222 {
       
   223     MDesCArray* itemList = iListbox->Model()->ItemTextArray();
       
   224     CDesCArray* itemArray = static_cast<CDesCArray*>(itemList);
       
   225 
       
   226     TInt lastListBoxPos = iListbox->CurrentItemIndex();
       
   227     TInt lastListBoxTopPos = iListbox->TopItemIndex();
       
   228 
       
   229     HBufC* itemValue = HBufC::NewLC(KMaxDataTypeLength);
       
   230     TPtr itemPtr = itemValue->Des();
       
   231     // add name
       
   232     iListBoxContent[aListBoxContentIndex] = aListItem;
       
   233     wstring name = aListItem.getName().getValue();
       
   234     itemPtr.Zero();
       
   235     itemPtr += _L("\t");
       
   236     TPtr ptr((unsigned short*)name.c_str(), name.size());
       
   237     ptr.SetLength(name.size());
       
   238     itemPtr += AknTextUtils::ChooseScalableText(ptr,*iCoeEnv->NormalFont(), NULL);
       
   239     itemPtr += _L("\t");
       
   240     itemPtr += _L("\t");
       
   241     // add value
       
   242     wstring value = aListItem.getValue(aSelectedItemIndex).getValue();
       
   243     ptr.Set((unsigned short*)value.c_str(), value.size(), value.size());
       
   244     ptr.SetLength(value.size());
       
   245     itemPtr += AknTextUtils::ChooseScalableText(ptr,*iCoeEnv->NormalFont(), NULL);
       
   246     itemArray->Delete(lastListBoxPos);
       
   247     itemArray->InsertL(lastListBoxPos, itemPtr);
       
   248 
       
   249     CleanupStack::PopAndDestroy(itemValue);
       
   250 
       
   251     // Handle content changes
       
   252     iListbox->Reset();
       
   253     // set indexes
       
   254     if (lastListBoxPos != -1)
       
   255     {
       
   256         iListbox->SetCurrentItemIndex(lastListBoxPos);
       
   257         iListbox->SetTopItemIndex(lastListBoxTopPos);
       
   258     }
       
   259     // Draw it
       
   260     iListbox->DrawDeferred();
       
   261 }
       
   262 
       
   263 void CAppMngr2MidletSettingsContainer::RefreshListBoxContentL(int aListBoxContentIndex ,int aSelectedItemIndex)
       
   264 {
       
   265     RefreshListBoxContentL(aListBoxContentIndex ,aSelectedItemIndex, iListBoxContent[aListBoxContentIndex]);
       
   266 }
       
   267 
       
   268 void CAppMngr2MidletSettingsContainer::RefreshListBoxContentL(const ListItem& aOldItem, const ListItem& aNewItem)
       
   269 {
       
   270     for (int i=0; i<iListBoxContent.size(); i++)
       
   271     {
       
   272         if (iListBoxContent[i].getName().getId() == aOldItem.getName().getId())
       
   273         {
       
   274             iListBoxContent[i] = aNewItem;
       
   275 
       
   276             MDesCArray* itemList = iListbox->Model()->ItemTextArray();
       
   277             CDesCArray* itemArray = static_cast<CDesCArray*>(itemList);
       
   278 
       
   279             int count = itemArray->Count();
       
   280 
       
   281             TPtr newValue((unsigned short*)aOldItem.getName().getValue().c_str(), aOldItem.getName().getValue().size());
       
   282             newValue.SetLength(aOldItem.getName().getValue().size());
       
   283 
       
   284             for (int i=0; i<count; i++)
       
   285             {
       
   286                 TPtrC oldValue = (*itemArray)[i];
       
   287                 if (oldValue.Find(newValue) > 0)
       
   288                 {
       
   289                     TInt lastListBoxPos = iListbox->CurrentItemIndex();
       
   290                     TInt lastListBoxTopPos = iListbox->TopItemIndex();
       
   291 
       
   292                     HBufC* itemValue = HBufC::NewLC(KMaxDataTypeLength);
       
   293                     TPtr itemPtr = itemValue->Des();
       
   294                     // add name
       
   295                     wstring name = aNewItem.getName().getValue();
       
   296                     itemPtr.Zero();
       
   297                     itemPtr += _L("\t");
       
   298                     TPtr ptr((unsigned short*)name.c_str(), name.size());
       
   299                     ptr.SetLength(name.size());
       
   300                     itemPtr += AknTextUtils::ChooseScalableText(ptr,*iCoeEnv->NormalFont(), NULL);
       
   301                     itemPtr += _L("\t");
       
   302                     itemPtr += _L("\t");
       
   303                     // add value
       
   304                     wstring value = aNewItem.getValue().getValue();
       
   305                     ptr.Set((unsigned short*)value.c_str(), value.size(), value.size());
       
   306                     ptr.SetLength(value.size());
       
   307                     itemPtr += AknTextUtils::ChooseScalableText(ptr,*iCoeEnv->NormalFont(), NULL);
       
   308 
       
   309                     itemArray->Delete(i);
       
   310                     itemArray->InsertL(i, itemPtr);
       
   311 
       
   312                     CleanupStack::PopAndDestroy(itemValue);
       
   313 
       
   314                     // Handle content changes
       
   315                     iListbox->Reset();
       
   316                     // set indexes
       
   317                     if (lastListBoxPos != -1)
       
   318                     {
       
   319                         iListbox->SetCurrentItemIndex(lastListBoxPos);
       
   320                         iListbox->SetTopItemIndex(lastListBoxTopPos);
       
   321                     }
       
   322                     // Draw it
       
   323                     iListbox->DrawDeferred();
       
   324 
       
   325                     break;
       
   326                 }
       
   327             }
       
   328 
       
   329             break;
       
   330         }
       
   331     }
       
   332 }
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // CAppMngr2MidletSettingsContainer::UpdateListBoxContentL
       
   336 //
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 void CAppMngr2MidletSettingsContainer::InitListBoxContentL(const vector<ListItem>& aListItems)
       
   340 {
       
   341     LOG(EJavaAppMngrPlugin, EInfo, " + CAppMngr2MidletSettingsContainer::UpdateListBoxContentL ");
       
   342     iListBoxContent = aListItems;
       
   343 
       
   344     TInt lastListBoxPos = iListbox->CurrentItemIndex();
       
   345     TInt lastListBoxTopPos = iListbox->TopItemIndex();
       
   346 
       
   347     MDesCArray* itemList = iListbox->Model()->ItemTextArray();
       
   348     CDesCArray* itemArray = static_cast<CDesCArray*>(itemList);
       
   349     itemArray->Reset();
       
   350 
       
   351     HBufC* itemValue = HBufC::NewLC(KMaxDataTypeLength);
       
   352     TPtr itemPtr = itemValue->Des();
       
   353 
       
   354     for (int i=0; i<aListItems.size(); i++)
       
   355     {
       
   356         if (!aListItems[i].getEnabled())
       
   357         {
       
   358             continue;
       
   359         }
       
   360         // add name
       
   361         itemPtr.Zero();
       
   362         itemPtr += _L("\t");
       
   363         wstring name = aListItems[i].getName().getValue();
       
   364         TPtr ptr((unsigned short*)name.c_str(), name.size());
       
   365         ptr.SetLength(name.size());
       
   366         itemPtr += AknTextUtils::ChooseScalableText(ptr,*iCoeEnv->NormalFont(), NULL);
       
   367         itemPtr += _L("\t");
       
   368         itemPtr += _L("\t");
       
   369         // add value
       
   370         wstring value = aListItems[i].getValue().getValue();
       
   371         ptr.Set((unsigned short*)value.c_str(), value.size(), value.size());
       
   372         ptr.SetLength(value.size());
       
   373         itemPtr += AknTextUtils::ChooseScalableText(ptr,*iCoeEnv->NormalFont(), NULL);
       
   374         itemArray->AppendL(itemPtr);
       
   375     }
       
   376 
       
   377     CleanupStack::PopAndDestroy(itemValue);
       
   378 
       
   379     // Handle content changes
       
   380     iListbox->Reset();
       
   381     // set indexes
       
   382     if (lastListBoxPos != -1)
       
   383     {
       
   384         iListbox->SetCurrentItemIndex(lastListBoxPos);
       
   385         iListbox->SetTopItemIndex(lastListBoxTopPos);
       
   386     }
       
   387     // Draw it
       
   388     iListbox->DrawDeferred();
       
   389 
       
   390     LOG(EJavaAppMngrPlugin, EInfo, " - CAppMngr2MidletSettingsContainer::UpdateListBoxContentL ");
       
   391 }
       
   392 
       
   393 const ListItem& CAppMngr2MidletSettingsContainer::GetListBoxItem(int aListBoxItemIndex)
       
   394 {
       
   395     return iListBoxContent[aListBoxItemIndex];
       
   396 }
       
   397 
       
   398 void CAppMngr2MidletSettingsContainer::SetListBoxItemValue(int aListBoxItemIndex, int aValue)
       
   399 {
       
   400     iListBoxContent[aListBoxItemIndex].setCurrentValue(aValue);
       
   401 }
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 // CAppMngr2MidletSettingsContainer::GetHelpContext(TCoeHelpContext& aContext)
       
   405 // Gives the help context to be displayed
       
   406 // ---------------------------------------------------------------------------
       
   407 //
       
   408 void CAppMngr2MidletSettingsContainer::GetHelpContext(TCoeHelpContext& aContext) const
       
   409 {
       
   410     LOG(EJavaAppMngrPlugin, EInfo, " + CAppMngr2MidletSettingsContainer::GetHelpContext ");
       
   411     aContext.iMajor = KOwnUid;
       
   412     aContext.iContext = HLP_JAVA_APPLICATION_SETTINGS;
       
   413     LOG(EJavaAppMngrPlugin, EInfo, " - CAppMngr2MidletSettingsContainer::GetHelpContext ");
       
   414 }
       
   415 
       
   416 
       
   417 // ---------------------------------------------------------
       
   418 // CAppMngr2MidletSettingsContainer::HandleResourceChange
       
   419 // Handles a resource relative event
       
   420 // ---------------------------------------------------------
       
   421 //
       
   422 void CAppMngr2MidletSettingsContainer::HandleResourceChange(TInt aType)
       
   423 {
       
   424     LOG(EJavaAppMngrPlugin, EInfo, " + CAppMngr2MidletSettingsContainer::HandleResourceChange ");
       
   425     CCoeControl::HandleResourceChange(aType);
       
   426 
       
   427     if (aType == KEikDynamicLayoutVariantSwitch) //Handle change in layout orientation
       
   428     {
       
   429         TRect mainPaneRect;
       
   430         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   431         SetRect(mainPaneRect);
       
   432         DrawNow();
       
   433     }
       
   434 
       
   435     LOG(EJavaAppMngrPlugin, EInfo, " - CAppMngr2MidletSettingsContainer::HandleResourceChange ");
       
   436 }
       
   437 
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CAppMngr2MidletSettingsContainer::FocusChanged
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 void CAppMngr2MidletSettingsContainer::FocusChanged(TDrawNow aDrawNow)
       
   444 {
       
   445     LOG(EJavaAppMngrPlugin, EInfo, " CAppMngr2MidletSettingsContainer::FocusChanged ");
       
   446     if (iListbox)
       
   447     {
       
   448         iListbox->SetFocus(IsFocused(), aDrawNow);
       
   449     }
       
   450 }
       
   451 
       
   452 // End of File