webengine/wmlengine/src/fbox/src/Epoc32FormImages.cpp
changeset 74 91031d3aab7d
parent 68 92a765b5b3e7
child 85 e358f2276d3f
equal deleted inserted replaced
68:92a765b5b3e7 74:91031d3aab7d
     1 /*
       
     2 * Copyright (c) 2000 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32def.h>  // First to avoid NULL redefine warning (no #ifndef NULL).
       
    20 #include "nw_fbox_epoc32formimagesi.h"
       
    21 
       
    22 #include "nw_fbox_checkbox.h"
       
    23 #include "nw_fbox_radiobox.h"
       
    24 #include "nw_fbox_optionbox.h"
       
    25 #include "nw_image_epoc32simpleimage.h"
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <fbs.h>
       
    29 #include <nwx_buffer.h>
       
    30 #include <nw_browser_browserimages.h>
       
    31 
       
    32 /* ------------------------------------------------------------------------- */
       
    33 const
       
    34 NW_FBox_FormImages_Class_t NW_FBox_FormImages_Class = {
       
    35   { /* NW_Object_Core       */
       
    36     /* super                */ &NW_Object_Base_Class,
       
    37     /* queryInterface       */ _NW_Object_Base_QueryInterface
       
    38   },
       
    39   { /* NW_FBox_FormImages   */
       
    40     /* numCheckBoxEntries   */ 0,
       
    41     /* checkBoxEntries      */ NULL,
       
    42     /* numCheckBoxEntries   */ 0,
       
    43     /* checkBoxEntries      */ NULL
       
    44   }
       
    45 };
       
    46 
       
    47 /* ------------------------------------------------------------------------- *
       
    48    final methods
       
    49  * ------------------------------------------------------------------------- */
       
    50 
       
    51 /* ------------------------------------------------------------------------- */
       
    52 const NW_Image_AbstractImage_t*
       
    53 NW_FBox_FormImages_GetImage(NW_FBox_FormImages_t* thisObj,
       
    54                             NW_Bool hasFocus,
       
    55                             NW_Bool state,
       
    56                             NW_FBox_FormBox_t* formBox)
       
    57     {
       
    58     NW_Int16 index;
       
    59     NW_Uint8 numEntries;
       
    60     const NW_Image_AbstractImage_t* image = NULL;
       
    61     const NW_FBox_FormImages_Entry_t* entry;
       
    62 
       
    63     /*lint --e{794} --e{550} Conceivable use of null pointer, Symbol not accessed */
       
    64 
       
    65     /* parameter assertion block */
       
    66     NW_ASSERT (thisObj != NULL);
       
    67     NW_ASSERT (NW_Object_IsInstanceOf (thisObj, &NW_FBox_FormImages_Class));
       
    68 
       
    69     numEntries = 0;
       
    70     entry = NULL;
       
    71     if (NW_Object_IsInstanceOf(formBox, &NW_FBox_RadioBox_Class))
       
    72         {
       
    73         numEntries = NW_FBox_FormImages_GetClassPart (thisObj).numRadioBoxEntries;
       
    74         entry = NW_FBox_FormImages_GetClassPart (thisObj).radioBoxEntries;
       
    75         }
       
    76     else if (NW_Object_IsInstanceOf(formBox, &NW_FBox_CheckBox_Class))
       
    77         {
       
    78         numEntries = NW_FBox_FormImages_GetClassPart (thisObj).numCheckBoxEntries;
       
    79         entry = NW_FBox_FormImages_GetClassPart (thisObj).checkBoxEntries;
       
    80         }
       
    81 
       
    82     /* iterate through the table looking for a match */
       
    83     for (index = numEntries; index >= 0; index--)
       
    84         {
       
    85         if ((hasFocus == entry->focus) &&  (state == entry->state))
       
    86             {
       
    87             break;
       
    88             }
       
    89         index++;
       
    90         entry++;
       
    91         }
       
    92 
       
    93     TFileName mbmDrive;
       
    94     Dll::FileName(mbmDrive);
       
    95     TParse parse;
       
    96     parse.Set(mbmDrive, NULL, NULL);
       
    97     mbmDrive = parse.Drive();
       
    98 
       
    99     HBufC* mbmFile = HBufC::New( KMaxFileName );
       
   100 
       
   101     if (mbmFile == NULL )
       
   102         {
       
   103         /* Could not allocate memory for mbmFile, return from function with NULL*/
       
   104         return NULL;
       
   105         }
       
   106 
       
   107     TPtr ptr(mbmFile->Des());
       
   108 
       
   109     ptr.Append(mbmDrive);
       
   110 
       
   111 	TFileName KBrowserBitmapsFolder;
       
   112 	//_LIT(KDC_APP_BITMAP_DIR,"\\resource\\apps\\localisablefiles\\"); 	//	Bitmap files (.mbm)
       
   113 
       
   114 	KBrowserBitmapsFolder += KDC_APP_BITMAP_DIR;
       
   115 	KBrowserBitmapsFolder += KBrowserBitmapsName;
       
   116 	KBrowserBitmapsFolder.ZeroTerminate();
       
   117 
       
   118 	ptr.Append(KBrowserBitmapsFolder);
       
   119 
       
   120     CFbsBitmap* bitmap = NULL;
       
   121     CFbsBitmap* mask = NULL;
       
   122 
       
   123     TRAPD(error, bitmap = new (ELeave)CFbsBitmap());
       
   124 
       
   125     error = bitmap->Load(mbmFile->Des(), entry->imageId);
       
   126 
       
   127     if (error == KErrNone)
       
   128         {
       
   129         /* Load mask for the image */
       
   130         TRAP(error, mask = new (ELeave)CFbsBitmap());
       
   131 
       
   132         error = mask->Load(mbmFile->Des(), entry->maskId);
       
   133         if (error == KErrNone)
       
   134             {
       
   135             /* Image loaded succesfully, create Kimono image object to hold it */
       
   136             TSize size = bitmap->SizeInPixels();
       
   137 
       
   138             NW_GDI_Dimension3D_t gdiSize;
       
   139             gdiSize.width = (NW_GDI_Metric_t)size.iWidth;
       
   140             gdiSize.height = (NW_GDI_Metric_t)size.iHeight;
       
   141             gdiSize.depth = 1;
       
   142 
       
   143             /* TODO: Here we are creating image object, but who will DELETE it ? */
       
   144             const NW_Image_Epoc32Simple_t* simpleImage =
       
   145                 NW_Image_Epoc32Simple_New(gdiSize, bitmap, mask, NW_TRUE, NW_FALSE,
       
   146                                           ERecognizedImage, NULL, 0, NULL);
       
   147 
       
   148             NW_ASSERT(simpleImage != NULL);
       
   149 
       
   150             image = NW_Image_AbstractImageOf(simpleImage);
       
   151             }
       
   152         else
       
   153             {
       
   154             delete mask;
       
   155             }
       
   156         }
       
   157     else
       
   158         {
       
   159         delete bitmap;
       
   160         }
       
   161 
       
   162     delete mbmFile;
       
   163     return image;
       
   164 }