chxavcheckboxlistsettingitem.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:5k
源码类别:

Symbian

开发平台:

Visual C++

  1. /************************************************************************
  2.  * chxavcheckboxlistsettingitem.cpp
  3.  * ----------------------
  4.  *
  5.  * Synopsis:
  6.  * 
  7.  * settings page item comprising checkbox list for configuring mask value
  8.  *
  9.  * Target:
  10.  * Symbian OS
  11.  *
  12.  *
  13.  * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
  14.  *
  15.  ************************************************************************/
  16. // Symbian includes...
  17. #include <aknlists.h>
  18. #include <aknutils.h>
  19. #include <aknselectionlist.h>
  20. // Includes from this project...
  21. #include "chxavutil.h"
  22. #include "chxavmisc.h"
  23. #include "hxsym_debug.h"
  24. #include "chxavcheckboxlistsettingitem.h"
  25. #define D_TCPSOCKET 0x10000000
  26. #define D_RESOLVER  0x10000000
  27. #define D_AP_MANAGER 0x20000000
  28. namespace
  29. {
  30. static const CHXAvUtil::KeyValEntry<TUint, const TCHAR*> g_maskTable[] = 
  31. {
  32.     // defined by our ui
  33.     Emit_(SYMP_INFO),
  34.     Emit_(SYMP_WSEVENTS),
  35.     Emit_(SYMP_FILE),
  36.     Emit_(SYMP_FILE_UI),
  37.     Emit_(SYMP_DIALOGS),
  38.     // defined in Helix core (in debug module and some private modules)
  39.     Emit_(D_ERROR),
  40.     Emit_(D_INFO),
  41.     Emit_(D_ALLOC),
  42.     Emit_(D_TCPSOCKET),
  43.     Emit_(D_AP_MANAGER)
  44. };
  45. } // locals
  46. ////////////////////////////////////////////
  47. //
  48. CHXAvCheckBoxListSettingItem::CHXAvCheckBoxListSettingItem(TInt aIdentifier, TUint& mask)
  49. : CAknSettingItem(aIdentifier)
  50. , m_mask(mask)
  51. {
  52. }
  53. ////////////////////////////////////////////
  54. //
  55. CHXAvCheckBoxListSettingItem::~CHXAvCheckBoxListSettingItem()
  56.     CleanupList();
  57. }
  58. ////////////////////////////////////////////
  59. //
  60. void CHXAvCheckBoxListSettingItem::CleanupList()
  61. {
  62.     if (m_pSelectionList)
  63.     {
  64.         // free items
  65.         m_pSelectionList->ResetAndDestroy();
  66.         HX_DELETE(m_pSelectionList);
  67.     }
  68. }
  69. const TDesC& CHXAvCheckBoxListSettingItem::SettingTextL()
  70. {
  71.     _LIT(KHexFormat, "0x%X");
  72.     m_textBuf.Format(KHexFormat, m_mask);
  73.     return m_textBuf;
  74. }
  75. void CHXAvCheckBoxListSettingItem::StoreL()
  76. {
  77.     // note: selection list will be null if page is not currently displayed
  78.     if( m_pSelectionList )
  79.     {
  80.         m_mask = CalculateMask();
  81.     }
  82.     CAknSettingItem::StoreL();
  83. }
  84. ////////////////////////////////////////////
  85. //
  86. TUint CHXAvCheckBoxListSettingItem::CalculateMask()
  87. {
  88.     HX_ASSERT(m_pSelectionList != 0);
  89.     TUint mask = 0;
  90.     TUint count = m_pSelectionList->Count();
  91.     for(TUint idx = 0; idx < count; ++idx)
  92.     {
  93.         CSelectableItem* pItem = m_pSelectionList->At(idx);
  94.         if( pItem->SelectionStatus() )
  95.         {
  96.             mask |= g_maskTable[idx].key;
  97.         }
  98.     }
  99.     return mask;
  100. }
  101. ////////////////////////////////////////////
  102. //
  103. CSelectionItemList* CHXAvCheckBoxListSettingItem::CreateListL()
  104. {
  105.     const TInt k_Granularity = 4; // arbitrary
  106.     CSelectionItemList* pList = new (ELeave) CSelectionItemList(k_Granularity);
  107.     AUTO_PUSH_POP(pList); // out
  108.     TUint count = ARRAY_COUNT(g_maskTable);
  109.     for (TUint idx = 0; idx < count; ++idx)
  110.     {  
  111.         TUint maskVal = g_maskTable[idx].key;
  112.         bool bIsOn = ((m_mask & maskVal) == maskVal);
  113.     
  114.         TPtrC maskText = reinterpret_cast<const TText*>((g_maskTable[idx].val));
  115.         CSelectableItem* pItem = new(ELeave)CSelectableItem(maskText, bIsOn);
  116.         AUTO_PUSH_POP(pItem);
  117.         pItem->ConstructL();
  118.         // transfer item ownership to list
  119.         pList->AppendL(pItem);
  120.     }
  121.     return pList;
  122. }
  123. ////////////////////////////////////////////
  124. // show the settings page associated with this settings item
  125. //
  126. void CHXAvCheckBoxListSettingItem::EditItemL( TBool /* aCalledFromMenu */)
  127. {
  128.     CleanupList();
  129.     
  130.     m_pSelectionList = CreateListL();
  131.     CHXAvCheckBoxListSettingPage* pDlg 
  132.         = new( ELeave )CHXAvCheckBoxListSettingPage(SettingPageResourceId(), m_pSelectionList);
  133.     // save cleanupstack init until LD
  134.     {
  135.         AUTO_PUSH_POP(pDlg);
  136.         SetSettingPage(pDlg);
  137.         pDlg->SetSettingPageObserver(this);
  138.    
  139.         SetUpStandardSettingPageL();
  140.     }
  141.     
  142.     pDlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged);
  143.     SetSettingPage(0);
  144. }
  145. void CHXAvCheckBoxListSettingItem::HandleSettingPageEventL (CAknSettingPage* /*pSettingPage*/,
  146.                                                          TAknSettingPageEvent eventType)
  147. {
  148.     DPRINTF(SYMP_INFO, ("HandleSettingPageEventL(): %dn", eventType));
  149.     switch(eventType)
  150.     {
  151.     case MAknSettingPageObserver::EEventSettingCancelled:
  152.         CleanupList();
  153.         break;
  154.     case MAknSettingPageObserver::EEventSettingOked:
  155.         StoreL();
  156.         // list box text (displayed in setting item) must be updated
  157.         UpdateListBoxTextL(); 
  158.         break;
  159.     default:
  160.         // nothing
  161.         break;
  162.     }
  163.     //CAknSettingItem::HandleSettingPageEventL(pSettingPage, eventType);
  164. }
  165. ////////////////////////////////////////////////
  166. // ctor
  167. CHXAvCheckBoxListSettingPage::CHXAvCheckBoxListSettingPage(TInt idRes, CSelectionItemList* pItemArray)
  168. : CAknCheckBoxSettingPage( idRes, pItemArray )
  169. {
  170. }
  171. ////////////////////////////////////////////////
  172. //
  173. void CHXAvCheckBoxListSettingPage::ProcessCommandL(TInt aCommandId)
  174. {
  175.     DPRINTF(SYMP_INFO, ("process command %dn", aCommandId));
  176.     switch (aCommandId)
  177.     {
  178. case EAknSoftkeySelect: 
  179.     HideMenu();
  180.     SelectCurrentItemL();
  181.     break;
  182. default:
  183.     CAknCheckBoxSettingPage::ProcessCommandL(aCommandId);
  184.     break;
  185.     }
  186. }