examples/ForumNokia/ImageConverter/src/EncoderSelectionDialog.cpp

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

Generated by  doxygen 1.6.2