examples/ForumNokia/DBMS/src/DBMSEditorView.cpp

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 #include <barsread.h>  // for resource reader
00006 #include <coemain.h>
00007 #include "DBMSEditorView.h"
00008 #include <DBMS.rsg> // Generated from DBMS.rss
00009 #include <eikfrlbd.h>
00010 #include <eiklabel.h>  // CEikLabel
00011 #include <AknUtils.h>
00012 
00013 // Constant texts
00014 _LIT(KLabelTextAuthor,"Author:");
00015 _LIT(KLabelTextTitle,"Title:");
00016 _LIT(KLabelTextDescription, "Description:");
00017 _LIT(KEmptyText, "None");
00018 
00019 // ---------------------------------------------------------------------------
00020 // CDBMSEditorView::NewL()
00021 //
00022 // Create instance of this compound control.
00023 // ---------------------------------------------------------------------------
00024 //
00025 CDBMSEditorView* CDBMSEditorView::NewL(const TRect& aRect)
00026     {
00027     CDBMSEditorView* self = new (ELeave) CDBMSEditorView;
00028     CleanupStack::PushL(self);
00029     self->ConstructL(aRect);
00030     CleanupStack::Pop(self);
00031     return self;
00032     }
00033 
00034 
00035 // ---------------------------------------------------------------------------
00036 // CDBMSEditorView::ConstructL()
00037 //
00038 // Perform the second phase construction. Instantiate the owned controls.
00039 // ---------------------------------------------------------------------------
00040 //
00041 void CDBMSEditorView::ConstructL(const TRect& aRect)
00042     {
00043     // Create a window for this application view
00044     CreateWindowL();
00045         
00046         iItemList = new (ELeave) CAknSettingItemList;
00047         iItemList->SetMopParent(this);
00048     iItemList->ConstructFromResourceL(R_ENTRY_SETTINGS_LIST); 
00049     
00050     LoadListL();
00051     
00052     iItemList->MakeVisible(ETrue);
00053     iItemList->SetRect(aRect);
00054     iItemList->ActivateL();
00055     iItemList->ListBox()->UpdateScrollBarsL();
00056     iItemList->DrawNow();    
00057 
00058     // Set the windows size
00059     SetRect(aRect);
00060 
00061     // Activate the window, which makes it ready to be drawn
00062     ActivateL();
00063 
00064     }
00065 
00066 
00067 // ----------------------------------------------------
00068 // CDBMSEditorView::LoadListL()
00069 // Loads item list dynamically.
00070 // ----------------------------------------------------
00071 //
00072 void CDBMSEditorView::LoadListL()
00073         {
00074         TBool isNumberedStyle = iItemList->IsNumberedStyle();
00075         CArrayPtr<CGulIcon>* icons = iItemList->ListBox()->ItemDrawer()->FormattedCellData()->IconArray();
00076         TBuf<50> aText;
00077         
00078         /*Author item*/
00079         
00080         iAuthor = new (ELeave) CAknTextSettingItem(1, aText);
00081         iAuthor->SetEmptyItemTextL( KEmptyText );
00082         // The same resource id can be used for multiple text setting pages.
00083         iAuthor->ConstructL(isNumberedStyle, 1, KLabelTextAuthor, icons, R_TEXT_SETTING_PAGE, -1);
00084         iItemList->SettingItemArray()->AppendL(iAuthor);
00085         
00086         /*Title item*/
00087         iTitle = new (ELeave) CAknTextSettingItem(2, aText);
00088         iTitle->SetEmptyItemTextL( KEmptyText );
00089         // The same resource id can be used for multiple text setting pages.
00090         iTitle->ConstructL(isNumberedStyle, 1, KLabelTextTitle, icons, R_TEXT_SETTING_PAGE, -1);
00091         iItemList->SettingItemArray()->AppendL(iTitle);
00092         
00093         /*Description item*/
00094         iDescription = new (ELeave) CAknTextSettingItem(3, aText);
00095         iDescription->SetEmptyItemTextL( KEmptyText );
00096         // The same resource id can be used for multiple text setting pages.
00097         iDescription->ConstructL(isNumberedStyle, 1, KLabelTextDescription, 
00098                 icons, R_TEXT_SETTING_PAGE, -1);
00099         iItemList->SettingItemArray()->AppendL(iDescription);
00100         
00101         // Required when there is only one setting item.
00102         iItemList->SettingItemArray()->RecalculateVisibleIndicesL();
00103 
00104         iItemList->HandleChangeInItemArrayOrVisibilityL();
00105 
00106         }
00107 // ---------------------------------------------------------------------------
00108 // CDBMSEditorView::CDBMSEditorView()
00109 //
00110 // // Constructor.
00111 // ---------------------------------------------------------------------------
00112 //
00113 CDBMSEditorView::CDBMSEditorView()
00114     {
00115     // No implementation required
00116     }
00117 
00118 
00119 // ---------------------------------------------------------------------------
00120 // CDBMSEditorView::~CDBMSEditorView()
00121 //
00122 // Destructor. Release the owned controls
00123 // ---------------------------------------------------------------------------
00124 //
00125 CDBMSEditorView::~CDBMSEditorView()
00126     {
00127     delete iItemList;
00128     }
00129 
00130 // ---------------------------------------------------------------------------
00131 // CDBMSEditorView::CountComponentControls()
00132 //
00133 // Tell the framework the number of owned controls so that it can query them
00134 // ---------------------------------------------------------------------------
00135 //
00136 TInt CDBMSEditorView::CountComponentControls() const
00137     {
00138     TInt count = 0;
00139         if (iItemList)
00140                 count++;
00141         return count;
00142     //return KNumberOfControls;
00143     }
00144 
00145 // ---------------------------------------------------------------------------
00146 // CDBMSEditorView::ComponentControl()
00147 //
00148 // Return owned controls to framework so it will draw them.
00149 // ---------------------------------------------------------------------------
00150 //
00151 CCoeControl* CDBMSEditorView::ComponentControl(TInt /*aIndex*/) const
00152     {
00153     return iItemList;
00154     }
00155 
00156 
00157 // ---------------------------------------------------------------------------
00158 // CDBMSEditorView::OfferKeyEventL()
00159 //
00160 // Handle key events. User of this view control must add this to control
00161 // stack to ensure this component is able to get key events. In practise
00162 // the AppUi does it.
00163 // ---------------------------------------------------------------------------
00164 //
00165 TKeyResponse CDBMSEditorView::OfferKeyEventL(const TKeyEvent& aKeyEvent,
00166                             TEventCode aType)
00167     {
00168     if(aType != EEventKey)
00169         {
00170         return EKeyWasNotConsumed;
00171         }    
00172     else if(iItemList)
00173         {
00174         return iItemList->OfferKeyEventL( aKeyEvent, aType );
00175         }
00176     else
00177         {
00178         return EKeyWasNotConsumed;
00179         }
00180     }
00181 
00182 // ---------------------------------------------------------------------------
00183 // CDBMSEditorView::GetAuthor()
00184 //
00185 // Get author value from iEdwinAuthor
00186 // ---------------------------------------------------------------------------
00187 //
00188 void CDBMSEditorView::GetAuthorL(TDes& aResult) const
00189     {
00190     aResult.Copy(iAuthor->SettingTextL());
00191     }
00192 
00193 
00194 // ---------------------------------------------------------------------------
00195 // CDBMSEditorView::GetTitle()
00196 //
00197 // Get title value from iEdwinTitle
00198 // ---------------------------------------------------------------------------
00199 //
00200 void CDBMSEditorView::GetTitleL(TDes& aResult) const
00201     {
00202         aResult.Copy(iTitle->SettingTextL());
00203     }
00204 
00205 
00206 // ---------------------------------------------------------------------------
00207 // CDBMSEditorView::GetDescription()
00208 //
00209 // Get description value from iEdwinDescription
00210 // ---------------------------------------------------------------------------
00211 //
00212 void CDBMSEditorView::GetDescriptionL(TDes& aResult) const
00213     {
00214     aResult.Copy(iDescription->SettingTextL());
00215     }
00216 
00217 // ----------------------------------------------------
00218 // CDBMSEditorView::Draw()
00219 // This function is used for window server-initiated 
00220 // redrawing of controls, and for some 
00221 // application-initiated drawing.
00222 // ----------------------------------------------------
00223 //
00224 void CDBMSEditorView::Draw(const TRect& /*aRect*/) const
00225     {
00226     // Get the standard graphics context 
00227     CWindowGc& gc = SystemGc();
00228     
00229     // Gets the control's extent
00230     TRect rect = Rect();
00231     
00232     // Clears the screen
00233     gc.Clear(rect);
00234     }
00235 
00236 // ---------------------------------------------------------
00237 // CDBMSEditorView::HandleResourceChange()
00238 // Called by framework when resource is changed.
00239 // ---------------------------------------------------------
00240 //
00241 
00242 void CDBMSEditorView::HandleResourceChange(TInt aType)
00243     {
00244     
00245     CCoeControl::HandleResourceChange(aType);
00246 
00247     // ADDED FOR SCALABLE UI SUPPORT
00248     // *****************************
00249         //if ( aType == KEikDynamicLayoutVariantSwitch )
00250         //hard coded constant so it can be compiled with first edition
00251     if ( aType==0x101F8121 )
00252         {
00253         TRect rect = Rect();
00254         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00255         SetRect(rect);
00256         iItemList->SetRect(rect);
00257         TRAP_IGNORE (iItemList->ListBox()->UpdateScrollBarsL();)
00258         iItemList->DrawNow();    
00259         } 
00260     }
00261     

Generated by  doxygen 1.6.2