examples/ForumNokia/DBMS/src/DBMSEditorView.cpp

00001 /*
00002  * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 #include <barsread.h>  // for resource reader
00031 #include <coemain.h>
00032 #include "DBMSEditorView.h"
00033 #include <DBMS.rsg> // Generated from DBMS.rss
00034 #include <eikfrlbd.h>
00035 #include <eiklabel.h>  // CEikLabel
00036 #include <AknUtils.h>
00037 
00038 // Constant texts
00039 _LIT(KLabelTextAuthor,"Author:");
00040 _LIT(KLabelTextTitle,"Title:");
00041 _LIT(KLabelTextDescription, "Description:");
00042 _LIT(KEmptyText, "None");
00043 
00044 // ---------------------------------------------------------------------------
00045 // CDBMSEditorView::NewL()
00046 //
00047 // Create instance of this compound control.
00048 // ---------------------------------------------------------------------------
00049 //
00050 CDBMSEditorView* CDBMSEditorView::NewL(const TRect& aRect)
00051     {
00052     CDBMSEditorView* self = new (ELeave) CDBMSEditorView;
00053     CleanupStack::PushL(self);
00054     self->ConstructL(aRect);
00055     CleanupStack::Pop(self);
00056     return self;
00057     }
00058 
00059 
00060 // ---------------------------------------------------------------------------
00061 // CDBMSEditorView::ConstructL()
00062 //
00063 // Perform the second phase construction. Instantiate the owned controls.
00064 // ---------------------------------------------------------------------------
00065 //
00066 void CDBMSEditorView::ConstructL(const TRect& aRect)
00067     {
00068     // Create a window for this application view
00069     CreateWindowL();
00070         
00071         iItemList = new (ELeave) CAknSettingItemList;
00072         iItemList->SetMopParent(this);
00073     iItemList->ConstructFromResourceL(R_ENTRY_SETTINGS_LIST); 
00074     
00075     LoadListL();
00076     
00077     iItemList->MakeVisible(ETrue);
00078     iItemList->SetRect(aRect);
00079     iItemList->ActivateL();
00080     iItemList->ListBox()->UpdateScrollBarsL();
00081     iItemList->DrawNow();    
00082 
00083     // Set the windows size
00084     SetRect(aRect);
00085 
00086     // Activate the window, which makes it ready to be drawn
00087     ActivateL();
00088 
00089     }
00090 
00091 
00092 // ----------------------------------------------------
00093 // CDBMSEditorView::LoadListL()
00094 // Loads item list dynamically.
00095 // ----------------------------------------------------
00096 //
00097 void CDBMSEditorView::LoadListL()
00098         {
00099         TBool isNumberedStyle = iItemList->IsNumberedStyle();
00100         CArrayPtr<CGulIcon>* icons = iItemList->ListBox()->ItemDrawer()->FormattedCellData()->IconArray();
00101         TBuf<50> aText;
00102         
00103         /*Author item*/
00104         
00105         iAuthor = new (ELeave) CAknTextSettingItem(1, aText);
00106         iAuthor->SetEmptyItemTextL( KEmptyText );
00107         // The same resource id can be used for multiple text setting pages.
00108         iAuthor->ConstructL(isNumberedStyle, 1, KLabelTextAuthor, icons, R_TEXT_SETTING_PAGE, -1);
00109         iItemList->SettingItemArray()->AppendL(iAuthor);
00110         
00111         /*Title item*/
00112         iTitle = new (ELeave) CAknTextSettingItem(2, aText);
00113         iTitle->SetEmptyItemTextL( KEmptyText );
00114         // The same resource id can be used for multiple text setting pages.
00115         iTitle->ConstructL(isNumberedStyle, 1, KLabelTextTitle, icons, R_TEXT_SETTING_PAGE, -1);
00116         iItemList->SettingItemArray()->AppendL(iTitle);
00117         
00118         /*Description item*/
00119         iDescription = new (ELeave) CAknTextSettingItem(3, aText);
00120         iDescription->SetEmptyItemTextL( KEmptyText );
00121         // The same resource id can be used for multiple text setting pages.
00122         iDescription->ConstructL(isNumberedStyle, 1, KLabelTextDescription, 
00123                 icons, R_TEXT_SETTING_PAGE, -1);
00124         iItemList->SettingItemArray()->AppendL(iDescription);
00125         
00126         // Required when there is only one setting item.
00127         iItemList->SettingItemArray()->RecalculateVisibleIndicesL();
00128 
00129         iItemList->HandleChangeInItemArrayOrVisibilityL();
00130 
00131         }
00132 // ---------------------------------------------------------------------------
00133 // CDBMSEditorView::CDBMSEditorView()
00134 //
00135 // // Constructor.
00136 // ---------------------------------------------------------------------------
00137 //
00138 CDBMSEditorView::CDBMSEditorView()
00139     {
00140     // No implementation required
00141     }
00142 
00143 
00144 // ---------------------------------------------------------------------------
00145 // CDBMSEditorView::~CDBMSEditorView()
00146 //
00147 // Destructor. Release the owned controls
00148 // ---------------------------------------------------------------------------
00149 //
00150 CDBMSEditorView::~CDBMSEditorView()
00151     {
00152     delete iItemList;
00153     }
00154 
00155 // ---------------------------------------------------------------------------
00156 // CDBMSEditorView::CountComponentControls()
00157 //
00158 // Tell the framework the number of owned controls so that it can query them
00159 // ---------------------------------------------------------------------------
00160 //
00161 TInt CDBMSEditorView::CountComponentControls() const
00162     {
00163     TInt count = 0;
00164         if (iItemList)
00165                 count++;
00166         return count;
00167     //return KNumberOfControls;
00168     }
00169 
00170 // ---------------------------------------------------------------------------
00171 // CDBMSEditorView::ComponentControl()
00172 //
00173 // Return owned controls to framework so it will draw them.
00174 // ---------------------------------------------------------------------------
00175 //
00176 CCoeControl* CDBMSEditorView::ComponentControl(TInt /*aIndex*/) const
00177     {
00178     return iItemList;
00179     }
00180 
00181 
00182 // ---------------------------------------------------------------------------
00183 // CDBMSEditorView::OfferKeyEventL()
00184 //
00185 // Handle key events. User of this view control must add this to control
00186 // stack to ensure this component is able to get key events. In practise
00187 // the AppUi does it.
00188 // ---------------------------------------------------------------------------
00189 //
00190 TKeyResponse CDBMSEditorView::OfferKeyEventL(const TKeyEvent& aKeyEvent,
00191                             TEventCode aType)
00192     {
00193     if(aType != EEventKey)
00194         {
00195         return EKeyWasNotConsumed;
00196         }    
00197     else if(iItemList)
00198         {
00199         return iItemList->OfferKeyEventL( aKeyEvent, aType );
00200         }
00201     else
00202         {
00203         return EKeyWasNotConsumed;
00204         }
00205     }
00206 
00207 // ---------------------------------------------------------------------------
00208 // CDBMSEditorView::GetAuthor()
00209 //
00210 // Get author value from iEdwinAuthor
00211 // ---------------------------------------------------------------------------
00212 //
00213 void CDBMSEditorView::GetAuthorL(TDes& aResult) const
00214     {
00215     aResult.Copy(iAuthor->SettingTextL());
00216     }
00217 
00218 
00219 // ---------------------------------------------------------------------------
00220 // CDBMSEditorView::GetTitle()
00221 //
00222 // Get title value from iEdwinTitle
00223 // ---------------------------------------------------------------------------
00224 //
00225 void CDBMSEditorView::GetTitleL(TDes& aResult) const
00226     {
00227         aResult.Copy(iTitle->SettingTextL());
00228     }
00229 
00230 
00231 // ---------------------------------------------------------------------------
00232 // CDBMSEditorView::GetDescription()
00233 //
00234 // Get description value from iEdwinDescription
00235 // ---------------------------------------------------------------------------
00236 //
00237 void CDBMSEditorView::GetDescriptionL(TDes& aResult) const
00238     {
00239     aResult.Copy(iDescription->SettingTextL());
00240     }
00241 
00242 // ----------------------------------------------------
00243 // CDBMSEditorView::Draw()
00244 // This function is used for window server-initiated 
00245 // redrawing of controls, and for some 
00246 // application-initiated drawing.
00247 // ----------------------------------------------------
00248 //
00249 void CDBMSEditorView::Draw(const TRect& /*aRect*/) const
00250     {
00251     // Get the standard graphics context 
00252     CWindowGc& gc = SystemGc();
00253     
00254     // Gets the control's extent
00255     TRect rect = Rect();
00256     
00257     // Clears the screen
00258     gc.Clear(rect);
00259     }
00260 
00261 // ---------------------------------------------------------
00262 // CDBMSEditorView::HandleResourceChange()
00263 // Called by framework when resource is changed.
00264 // ---------------------------------------------------------
00265 //
00266 
00267 void CDBMSEditorView::HandleResourceChange(TInt aType)
00268     {
00269     
00270     CCoeControl::HandleResourceChange(aType);
00271 
00272     // ADDED FOR SCALABLE UI SUPPORT
00273     // *****************************
00274         //if ( aType == KEikDynamicLayoutVariantSwitch )
00275         //hard coded constant so it can be compiled with first edition
00276     if ( aType==0x101F8121 )
00277         {
00278         TRect rect = Rect();
00279         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00280         SetRect(rect);
00281         iItemList->SetRect(rect);
00282         TRAP_IGNORE (iItemList->ListBox()->UpdateScrollBarsL();)
00283         iItemList->DrawNow();    
00284         } 
00285     }
00286     

Generated by  doxygen 1.6.2