00001 /* 00002 Copyright (c) 2002-2011 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: Application view implementation 00028 */ 00029 00030 00031 // INCLUDE FILES 00032 #include <GDI.H> 00033 #include <coemain.h> 00034 #include <EIKENV.H> 00035 #include "GfxIclView.h" 00036 #include <ImageConversion.h> 00037 00038 00039 00040 class CGfxImageDecoder : public CActive 00041 { 00042 public: 00043 CGfxImageDecoder(CFbsBitmap* aBitmap, CFbsBitmap* aMask, MGfxImageDecoderHandler& aHandler); 00044 ~CGfxImageDecoder(); 00045 00046 void LoadImageL(const TDesC& aFilename); 00047 void RunL() ; 00048 void DoCancel(); 00049 00050 private: 00051 CImageDecoder* iDecoder; 00052 CFbsBitmap* iBitmap; 00053 MGfxImageDecoderHandler& iHandler; 00054 RFs iFs; 00055 }; 00056 00057 // ============================ MEMBER FUNCTIONS =============================== 00058 00059 // ----------------------------------------------------------------------------- 00060 // CGfxDirectScreenBitmapView::NewL() 00061 // Two-phased constructor. 00062 // ----------------------------------------------------------------------------- 00063 // 00064 CGfxIclView* CGfxIclView::NewL( const TRect& aRect ) 00065 { 00066 CGfxIclView* self = CGfxIclView::NewLC( aRect ); 00067 CleanupStack::Pop( self ); 00068 return self; 00069 } 00070 00071 // ----------------------------------------------------------------------------- 00072 // CGfxDirectScreenBitmapView::NewLC() 00073 // Two-phased constructor. 00074 // ----------------------------------------------------------------------------- 00075 // 00076 CGfxIclView* CGfxIclView::NewLC( const TRect& aRect ) 00077 { 00078 CGfxIclView* self = new ( ELeave ) CGfxIclView; 00079 CleanupStack::PushL( self ); 00080 self->ConstructL( aRect ); 00081 return self; 00082 } 00083 00084 // ----------------------------------------------------------------------------- 00085 // CGfxDirectScreenBitmapView::ConstructL() 00086 // Symbian 2nd phase constructor can leave. 00087 // ----------------------------------------------------------------------------- 00088 // 00089 void CGfxIclView::ConstructL( const TRect& aRect ) 00090 { 00091 // Create a window for this application view 00092 CreateWindowL(); 00093 00094 // Set the windows size 00095 SetRect( aRect ); 00096 00097 00098 // Activate the window, which makes it ready to be drawn 00099 ActivateL(); 00100 } 00101 00102 // ----------------------------------------------------------------------------- 00103 // CGfxDirectScreenBitmapView::CGfxDirectScreenBitmapView() 00104 // C++ default constructor can NOT contain any code, that might leave. 00105 // ----------------------------------------------------------------------------- 00106 // 00107 CGfxIclView::CGfxIclView() 00108 { 00109 // No implementation required 00110 } 00111 00112 00113 // ----------------------------------------------------------------------------- 00114 // CGfxDirectScreenBitmapView::~CGfxDirectScreenBitmapView() 00115 // Destructor. 00116 // ----------------------------------------------------------------------------- 00117 // 00118 CGfxIclView::~CGfxIclView() 00119 { 00120 delete iImageDecoder; 00121 delete iLoadingBmp; 00122 delete iBitmap; 00123 } 00124 00125 00126 // ----------------------------------------------------------------------------- 00127 // CGfxDirectScreenBitmapView::Draw() 00128 // Draws the display. 00129 // ----------------------------------------------------------------------------- 00130 // 00131 void CGfxIclView::Draw( const TRect& /*aRect*/ ) const 00132 { 00133 // Get the standard graphics context 00134 CWindowGc& gc = SystemGc(); 00135 00136 // Gets the control's extent 00137 TRect drawRect( Rect()); 00138 00139 // Clears the screen 00140 gc.Clear( drawRect ); 00141 00142 // If the bitmap has fully loaded, then draw it 00143 if(iBitmap) 00144 { 00145 gc.BitBlt(TPoint(0,0), iBitmap); 00146 } 00147 00148 } 00149 00150 // ----------------------------------------------------------------------------- 00151 // CGfxDirectScreenBitmapView::SizeChanged() 00152 // Called by framework when the view size is changed. 00153 // ----------------------------------------------------------------------------- 00154 // 00155 void CGfxIclView::SizeChanged() 00156 { 00157 DrawNow(); 00158 } 00159 // End of File 00160 00161 00162 00163 00164 CGfxImageDecoder::CGfxImageDecoder(CFbsBitmap* aBitmap, CFbsBitmap* /*aMask*/, MGfxImageDecoderHandler& aHandler): 00165 CActive(0), 00166 iBitmap(aBitmap), 00167 iHandler(aHandler) 00168 { 00169 CActiveScheduler::Add(this); 00170 } 00171 00172 CGfxImageDecoder::~CGfxImageDecoder() 00173 { 00174 Cancel(); 00175 iFs.Close(); 00176 delete iDecoder; 00177 } 00178 00179 00180 void CGfxImageDecoder::RunL() 00181 { 00182 iHandler.GfxImageLoadedCallBack(iStatus.Int()); 00183 } 00184 00185 void CGfxImageDecoder::DoCancel() 00186 { 00187 iDecoder->Cancel(); 00188 } 00189 00190 void CGfxImageDecoder::LoadImageL(const TDesC& aFilename) 00191 { 00192 00193 User::LeaveIfError(iFs.Connect()); 00194 00195 iDecoder = CImageDecoder::FileNewL(iFs, aFilename); 00196 TFrameInfo info = iDecoder->FrameInfo(); 00197 00198 User::LeaveIfError( iBitmap->Create(info.iOverallSizeInPixels, info.iFrameDisplayMode) ); 00199 00200 iDecoder->Convert(&iStatus, *iBitmap); 00201 SetActive(); 00202 } 00203 00204 00205 void CGfxIclView::GfxImageLoadedCallBack(TInt /*aError*/) 00206 { 00207 iBitmap = iLoadingBmp; 00208 iLoadingBmp = NULL; 00209 00210 DrawNow(); 00211 } 00212 00213 void CGfxIclView::StartL() 00214 { 00215 iLoadingBmp = new(ELeave) CFbsBitmap(); 00216 iImageDecoder = new(ELeave) CGfxImageDecoder(iLoadingBmp, NULL, *this); 00217 iImageDecoder->LoadImageL(_L("c:\\data\\images\\robot.bmp")); 00218 } 00219 00220 void CGfxIclView::StopL() 00221 { 00222 }