webengine/wmlengine/src/utils/include/nwx_defs.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 1999 - 2001 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 /***************************************************************************
       
    20 **   File: nwx_defs.h
       
    21 **   Purpose:  Contains definitions common to all components. 
       
    22 **              Also contains defs for all of the Basic Scalar types
       
    23 **************************************************************************/
       
    24 #ifndef NWX_DEFS_H
       
    25 #define NWX_DEFS_H
       
    26 
       
    27 /*
       
    28 **----------------------------------------------------------------------
       
    29 ** Preprocessor Macro Definitions
       
    30 **----------------------------------------------------------------------
       
    31 */
       
    32 #ifdef __cplusplus
       
    33 extern "C" {
       
    34 #endif
       
    35 
       
    36 /*
       
    37 **----------------------------------------------------------------------
       
    38 ** Includes
       
    39 **----------------------------------------------------------------------
       
    40 */
       
    41 
       
    42 /*
       
    43  *  ANSI/ISO C header files needed to define basic data types
       
    44  * (ie. NULL, etc)
       
    45  */
       
    46 
       
    47 #include <stdlib.h>
       
    48 
       
    49 
       
    50 /*
       
    51 **----------------------------------------------------------------------
       
    52 ** Type Declarations
       
    53 **----------------------------------------------------------------------
       
    54 */
       
    55 
       
    56 #define _NW_STR(str) L ## str
       
    57 #define NW_STR(str) _NW_STR(str)
       
    58 
       
    59 /* New type definitions with non-conflicting name scheme */
       
    60 typedef unsigned char           NW_Bool;        /* NW_FALSE, NW_TRUE  */
       
    61 typedef unsigned char           NW_Byte;        /* 0 ... 0xFF         */
       
    62 typedef unsigned short          NW_Word;        /* 0 ... 0xFFFF       */
       
    63 typedef unsigned long           NW_Dword;       /* 0 ... 0xFFFFFFFF   */
       
    64 
       
    65 typedef unsigned char           NW_Uint8;       /* 0 ... 255          */
       
    66 typedef unsigned short          NW_Uint16;      /* 0 ... 65535        */
       
    67 typedef unsigned long           NW_Uint32;      /* 0 ... 4294967295   */
       
    68 
       
    69 typedef signed   char           NW_Int8;        /* -128 ... +127      */
       
    70 typedef signed   short          NW_Int16;       /* -32768 ... +32767  */
       
    71 typedef signed   long           NW_Int32;       /* -2147483648 ... +2147483647 */
       
    72 
       
    73 typedef float                   NW_Float32;
       
    74 typedef double                  NW_Float64;
       
    75 
       
    76 typedef unsigned short          NW_Ucs2;        /* 0 ... 65535        */
       
    77 typedef unsigned long           NW_Ucs4;        /* 0 ... 4294967295   */
       
    78 
       
    79 /*This type can hold both TBrowserStatusCode and http status*/
       
    80 typedef NW_Int32      NW_WaeError_t;
       
    81 typedef NW_Uint16     NW_WaeHttpStatus_t;
       
    82 
       
    83 
       
    84 #define NW_TRUE         ((NW_Bool)  0x01U)
       
    85 #define NW_FALSE        ((NW_Bool)  0x00U)
       
    86 
       
    87 #define NW_UINT8_MIN    ((NW_Uint8)  0x00U)
       
    88 #define NW_UINT8_MAX    ((NW_Uint8)  0xFFU)
       
    89 
       
    90 #define NW_UINT16_MIN   ((NW_Uint16) 0x0000U)
       
    91 #define NW_UINT16_MAX   ((NW_Uint16) 0xFFFFU)
       
    92 
       
    93 #define NW_UINT32_MIN   ((NW_Uint32) 0x00000000U)
       
    94 #define NW_UINT32_MAX   ((NW_Uint32) 0xFFFFFFFFU)
       
    95 
       
    96 #define NW_INT8_MIN     ((NW_Int8)   0x80U)
       
    97 #define NW_INT8_MAX     ((NW_Int8)   0x7FU)
       
    98 
       
    99 #define NW_INT16_MIN    ((NW_Int16)  0x8000U)
       
   100 #define NW_INT16_MAX    ((NW_Int16)  0x7FFFU)
       
   101 
       
   102 #define NW_INT32_MIN    ((NW_Int32)  0x80000000U)
       
   103 #define NW_INT32_MAX    ((NW_Int32)  0x7FFFFFFFU)
       
   104 
       
   105 /* 
       
   106  * Definitions needed by the script engine for 
       
   107  * performing IEEE floating point math.
       
   108  * These *should* be platform independent constants defined
       
   109  * by the IEEE specifications, but in all cases they
       
   110  * can be found in the ANSI/ISO C header file <float.h> 
       
   111  */
       
   112 #define NW_FLOAT32_DIG      FLT_DIG
       
   113 #define NW_FLOAT32_MIN      FLT_MIN
       
   114 #define NW_FLOAT32_MAX      FLT_MAX
       
   115 #define NW_FLOAT32_MIN_EXP  FLT_MIN_10_EXP
       
   116 #define NW_FLOAT32_MAX_EXP  FLT_MAX_10_EXP
       
   117 
       
   118 #define NW_MIN(x, y) ( ((x) < (y)) ? (x) : (y) )
       
   119 #define NW_MAX(x, y) ( ((x) > (y)) ? (x) : (y) )
       
   120 
       
   121 /*
       
   122  * When casting to unsigned types, the comparison "-expr <= 0" is used
       
   123  * rather than  "expr >= 0" to prevent warnings about unnecessary
       
   124  * comparisons on Epoc hardware.
       
   125  */
       
   126 #define NW_UINT8_CAST(expr) \
       
   127         ( (NW_ASSERT((-(NW_Int32)(expr)) <= 0 && \
       
   128                      ((NW_Uint32)(expr)) <= NW_UINT8_MAX)), \
       
   129           ((NW_Uint8)(expr)) )
       
   130 
       
   131 #define NW_UINT16_CAST(expr) \
       
   132         ( (NW_ASSERT((-(NW_Int32)(expr)) <= 0 && \
       
   133                      ((NW_Uint32)(expr)) <= NW_UINT16_MAX)), \
       
   134           ((NW_Uint16)(expr)) )
       
   135 
       
   136 #define NW_UINT32_CAST(expr) \
       
   137         ( (NW_ASSERT((-(NW_Int32)(expr)) <= 0 && \
       
   138                      ((NW_Uint32)(expr)) <= NW_UINT32_MAX)), \
       
   139           ((NW_Uint32)(expr)) )
       
   140 
       
   141 #define NW_INT8_CAST(expr) \
       
   142         ( (NW_ASSERT(((NW_Int32)(expr)) >= NW_INT8_MIN && \
       
   143                      ((NW_Int32)(expr)) <= NW_INT8_MAX)), \
       
   144           ((NW_Int8)(expr)) )
       
   145 
       
   146 #define NW_INT16_CAST(expr) \
       
   147         ( (NW_ASSERT(((NW_Int32)(expr)) >= NW_INT16_MIN && \
       
   148                      ((NW_Int32)(expr)) <= NW_INT16_MAX)), \
       
   149           ((NW_Int16)(expr)) )
       
   150 
       
   151 #define NW_INT32_CAST(expr) \
       
   152         ( (NW_ASSERT(((NW_Int32)(expr)) >= NW_INT32_MIN && \
       
   153                      ((NW_Int32)(expr)) <= NW_INT32_MAX)), \
       
   154           ((NW_Int32)(expr)) )
       
   155 
       
   156 #define NW_BOOL_CAST(expr) \
       
   157         ( ((NW_Bool)(((NW_Int32)(expr) != 0) ? NW_TRUE : NW_FALSE)) )
       
   158 
       
   159 /* 
       
   160  * Used to supress compiler warnings about required, 
       
   161  * but unused function parameters 
       
   162  */
       
   163 #define NW_REQUIRED_PARAM(param) if (param) {};
       
   164 
       
   165 /* NW_Opaque_t is used for passing dynamically typed
       
   166    values between the Script engine and the browser.  */
       
   167   
       
   168 typedef enum 
       
   169 {
       
   170   NW_OPAQUE_VALUE_TYPE_INT32,
       
   171   NW_OPAQUE_VALUE_TYPE_STRING,
       
   172   NW_OPAQUE_VALUE_TYPE_BOOL,
       
   173   NW_OPAQUE_VALUE_TYPE_FLOAT,
       
   174   NW_OPAQUE_VALUE_TYPE_INVALID
       
   175 } NW_Opaque_Value_Type_t;
       
   176 
       
   177 typedef struct _NW_Opaque_t NW_Opaque_t;
       
   178 
       
   179 /* Note: use "volatile" keyword to suppress compiler optimizer bug */
       
   180 /*       which changes store/load operation into a data-type cast */
       
   181 struct _NW_Opaque_t {
       
   182   volatile union {
       
   183     NW_Ucs2     *s;
       
   184     NW_Int32    i;
       
   185     NW_Float32  f;
       
   186     NW_Bool     b;
       
   187   } value;
       
   188   NW_Opaque_Value_Type_t type;
       
   189 };
       
   190 
       
   191 /* Facilitates run-time error checking */
       
   192 #define NW_THROWIF_MEM(_call) {if ((_call) == NULL) goto _NW_CATCH_MEM;}
       
   193 #define NW_THROW_ERROR() { goto _NW_CATCH_ERROR;}
       
   194 #define NW_THROWIF(_call) {if ((_call)) goto _NW_CATCH_ERROR;}
       
   195 #define NW_THROWIF_ERROR(_call) {if ((_call) != KBrsrSuccess) goto _NW_CATCH_ERROR;}
       
   196 #define NW_THROWIF_NULL(_call) {if ((_call) == NULL) goto _NW_CATCH_ERROR;}
       
   197 
       
   198 #define NW_CATCH_MEM _NW_CATCH_MEM:
       
   199 #define NW_CATCH_ERROR _NW_CATCH_ERROR:
       
   200 
       
   201 /*
       
   202 **----------------------------------------------------------------------
       
   203 ** Includes
       
   204 **----------------------------------------------------------------------
       
   205 */
       
   206 #include "nwx_assert.h"
       
   207 #include "nwx_mem.h"
       
   208 #include "BrsrStatusCodes.h"
       
   209 
       
   210 
       
   211 /* ------------------------------------------------------------------------- *
       
   212    public constants
       
   213  * ------------------------------------------------------------------------- */
       
   214 #define NW_HED_UrlRequest_Reason_Undefined     0  /* Shouldn't be used */
       
   215 #define NW_HED_UrlRequest_Reason_ShellLoad     1  /* used by goto and bookmark dialogs */ 
       
   216 #define NW_HED_UrlRequest_Reason_ShellPrev     2  /* used by history */
       
   217 #define NW_HED_UrlRequest_Reason_ShellNext     3  /* used by history */
       
   218 #define NW_HED_UrlRequest_Reason_ShellReload   4  /* used by history */
       
   219 #define NW_HED_UrlRequest_Reason_DocLoad       5  /* used by content-handlers to load new top-level documents */
       
   220 #define NW_HED_UrlRequest_Reason_DocPrev       6  /* used by Wml1x content-handler to load new top-level document as the result of the PREV task */
       
   221 #define NW_HED_UrlRequest_Reason_DocLoadChild  7  /* used by content-handlers to load embedded documents */
       
   222 #define NW_HED_UrlRequest_Reason_RestorePrev   8  /* used to restore a failed page */
       
   223 #define NW_HED_UrlRequest_Reason_RestoreNext   9  /* used to restore a failed page */
       
   224 #define NW_HED_UrlRequest_Reason_DocLoadHead   10 
       
   225 
       
   226 
       
   227 #ifdef __cplusplus
       
   228 } /* extern "C" */
       
   229 #endif
       
   230 
       
   231 #endif  /* NWX_DEFS_H */
       
   232 
       
   233 
       
   234