examples/ForumNokia/ImageConverter/src/EncoderSelectionDialog.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 FILES
00031 #include <aknlists.h>
00032 #include <ImageConversion.h>
00033 
00034 #include "ImageConverter.hrh"
00035 #include "EncoderSelectionDialog.h"
00036 #include "ImageConverterEngine.h"
00037 
00038 const TInt KNumMessages = 10;
00039 const TInt KMaxEncoderListLength = 80;
00040 const TInt KPeriodicTimerInterval(100000);
00041 
00042 // ================= MEMBER FUNCTIONS =======================
00043 
00044 // C++ default constructor can NOT contain any code, that
00045 // might leave.
00046 //
00047 CEncoderSelectionDialog::CEncoderSelectionDialog( 
00048     RImageTypeDescriptionArray& aImageTypes, 
00049     TInt& aSelectedIdx ) : 
00050     iImageTypes( aImageTypes ), iSelectedIdx( aSelectedIdx )
00051     {
00052     }
00053 
00054 CEncoderSelectionDialog::~CEncoderSelectionDialog()
00055     {
00056     if(iPeriodic)
00057         {
00058         iPeriodic->Cancel();
00059         }
00060     delete iPeriodic;
00061     }
00062 
00063 
00064 // ----------------------------------------------------------
00065 // CEncoderSelectionDialog::PreLayoutDynInitL()
00066 // Initializing the dialog dynamically
00067 // ----------------------------------------------------------
00068 //
00069 void CEncoderSelectionDialog::PreLayoutDynInitL()
00070     {
00071     SetEditableL(ETrue);
00072 
00073     // Initialize component array
00074     InitComponentArrayL();
00075     
00076     // Create a control to display a list of messages
00077     iListBox = new (ELeave) CAknSingleStyleListBox;
00078     iListBox->SetContainerWindowL(*this);
00079     iListBox->ConstructL(this);
00080     iListBox->SetListBoxObserver(this);
00081     
00082     iListBox->CreateScrollBarFrameL(ETrue);
00083     iListBox->ScrollBarFrame()->
00084         SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, 
00085                                 CEikScrollBarFrame::EAuto);
00086 
00087     Components().AppendLC(iListBox);
00088     CleanupStack::Pop(iListBox);
00089     
00090     
00091     // Create an array to hold the messages
00092     iMessageList = new (ELeave) CDesCArrayFlat(KNumMessages);
00093 
00094     // Give it to the control
00095     CTextListBoxModel* model = iListBox->Model();
00096     model->SetItemTextArray(iMessageList);
00097     model->SetOwnershipType(ELbmOwnsItemArray); // transfer ownership
00098     }
00099 
00100 void CEncoderSelectionDialog::PostLayoutDynInitL()
00101     {
00102     // add the message to the list
00103     iListBox->SetRect( Rect() );    
00104 
00105     
00106     _LIT( KTab, "\t" );
00107 
00108     for( TInt i=0; i<iImageTypes.Count(); i++ ) 
00109         {
00110         TBuf<KMaxEncoderListLength> desc;
00111 
00112         desc.Append( KTab );
00113         desc.Append( iImageTypes[i]->Description() );
00114     
00115         iMessageList->AppendL( desc );
00116         }
00117 
00118     // tell the control about the change
00119     iListBox->HandleItemAdditionL();
00120     }
00121 
00122 
00123 // ----------------------------------------------------------
00124 // CEncoderSelectionDialog::OkToExitL()
00125 // This function ALWAYS returns ETrue
00126 // ----------------------------------------------------------
00127 //
00128 TBool CEncoderSelectionDialog::OkToExitL(TInt /*aButtonId*/)
00129     {
00130     iSelectedIdx = iListBox->CurrentItemIndex();
00131     return ETrue;
00132     }
00133 
00134 TInt CEncoderSelectionDialog::CountComponentControls() const
00135     {
00136     TInt count = 0;
00137     if( iListBox )
00138         count = 1;
00139 
00140     return count;
00141     }
00142 
00143 CCoeControl* CEncoderSelectionDialog::ComponentControl(TInt /*aIndex*/) const
00144     {
00145     return iListBox;
00146     }
00147 
00148 TKeyResponse CEncoderSelectionDialog::OfferKeyEventL(
00149     const TKeyEvent& aKeyEvent,TEventCode aType)
00150     {
00151     if( iListBox )
00152         {
00153         if (aKeyEvent.iCode == EKeyOK)
00154             {
00155             iSelectedIdx = iListBox->CurrentItemIndex();
00156             TryExitL(1);
00157                 return( EKeyWasConsumed );
00158             }
00159         else
00160             {
00161             return( iListBox->OfferKeyEventL(aKeyEvent, aType) );
00162             }
00163         }
00164     else
00165        return( EKeyWasNotConsumed );
00166     }
00167 
00168 void CEncoderSelectionDialog::SizeChanged()
00169     {
00170     iListBox->SetRect(Rect());
00171     }
00172 
00173 void CEncoderSelectionDialog::HandleResourceChange(TInt aType)
00174     {
00175     CAknDialog::HandleResourceChange(aType);
00176     
00177     if ( aType==KEikDynamicLayoutVariantSwitch )
00178         {
00179         TRect rect;
00180         AknLayoutUtils::LayoutMetricsRect(
00181         AknLayoutUtils::EMainPane,rect);
00182 
00183         SetRect(rect);
00184         }
00185         
00186     }
00187 
00188 void CEncoderSelectionDialog::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
00189     {
00190     if (aEventType==EEventEnterKeyPressed || aEventType==EEventItemDoubleClicked)
00191         {
00192         iSelectedIdx = iListBox->CurrentItemIndex();
00193         
00194         // NOTE: Need to cut method calling flow
00195         // Wait as asynchronoysly 10ms and call TryExitL() after that  
00196         if (!iPeriodic)
00197             {
00198             iPeriodic = CPeriodic::NewL(CActive::EPriorityIdle);
00199             iPeriodic->Start(KPeriodicTimerInterval, KPeriodicTimerInterval,TCallBack(PeriodicTimerCallBack, this));
00200             }
00201         }
00202     }
00203 
00204 
00205 TInt CEncoderSelectionDialog::PeriodicTimerCallBack(TAny* aAny)
00206     {
00207     CEncoderSelectionDialog* self = static_cast<CEncoderSelectionDialog*>( aAny );
00208     self->iPeriodic->Cancel();
00209     TRAPD(err,
00210             self->TryExitL(1);
00211     );
00212     return KErrNone;
00213     }
00214 
00215 
00216 

Generated by  doxygen 1.6.2