Back to index

lightning-sunbird  0.9+nobinonly
port.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 //
00038 
00039 #ifndef PORT_H
00040 #define PORT_H
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 /*****************************************************************\
00047  *                                                               *
00048  *  PORT.H                                                       *
00049  *                                                               *
00050  *  Win16/Win32 portability stuff                                *
00051  *                                                               *
00052  *  A.Sokolsky                                                   *
00053  *      3.10.94 distilled into this header                       *
00054  *                                                               *
00055 \*****************************************************************/
00056 
00057 /*
00058  * calling conventions
00059  */
00060 #include <assert.h>
00061                                                       
00062                                                       
00063 #ifndef CDECL
00064 #define CDECL __cdecl
00065 #endif  // CDECL
00066 
00067 #ifndef PASCAL
00068 #define PASCAL __pascal
00069 #endif  // PASCAL
00070 
00071 #ifdef FASTCALL
00072 #error FASTCALL defined
00073 #endif // FASTCALL
00074 
00075 
00076 #ifdef NDEBUG
00077 #define FASTCALL __fastcall
00078 #else
00079 #define FASTCALL PASCAL
00080 #endif // NDEBUG   
00081 
00082 
00083 
00084 #ifndef HWND2DWORD
00085 #  ifdef WIN32
00086 #    define HWND2DWORD(X_hWnd) ( (DWORD)(X_hWnd) )
00087 #  else // WIN16
00088 #    define HWND2DWORD(X_hWnd) ( (DWORD)MAKELONG(((WORD)(X_hWnd)), 0) )
00089 #  endif
00090 #endif // HWND2DWORD
00091 
00092 
00093 /*
00094  * WIN16 - WIN32 compatibility stuff
00095  */
00096 
00097 #ifdef WIN32
00098 
00099 # define DLLEXPORT    __declspec( dllexport )
00100 # define EXPORT
00101 # define LOADDS
00102 # define HUGE
00103 # ifndef FAR
00104 #  define FAR
00105 # endif // FAR
00106 # ifndef NEAR
00107 #  define NEAR
00108 # endif // NEAR 
00109 # ifdef UNICODE
00110 #  define SIZEOF(x)   (sizeof(x)/sizeof(WCHAR))
00111 # else
00112 #  define SIZEOF(x)   sizeof(x)
00113 # endif
00114 
00115 #else  // !WIN32 == WIN16
00116 
00117 # define DLLEXPORT    
00118 # define EXPORT       __export
00119 # define LOADDS       __loadds
00120 # define HUGE         __huge
00121 # ifndef FAR
00122 #   define FAR        __far
00123 #   define NEAR       __near
00124 # endif  // FAR
00125 # define CONST const
00126 # define SIZEOF(x)    sizeof(x)
00127 # define CHAR char
00128 # define TCHAR char
00129 # define WCHAR char
00130 # ifndef LPTSTR
00131 #   define LPTSTR LPSTR
00132 # endif
00133 # ifndef LPCTSTR 
00134 #   define LPCTSTR LPCSTR
00135 # endif
00136 # define UNREFERENCED_PARAMETER(x) x;
00137 # ifndef TEXT
00138 #   define TEXT(x) x
00139 # endif
00140 # define GetWindowTextW GetWindowText
00141 # define lstrcpyW lstrcpy   
00142 
00143 # define BN_DBLCLK BN_DOUBLECLICKED // ~~MRJ needed for custom control.
00144 // ~~MRJ begin Win95 backward compat section
00145 # define LPWSTR LPSTR
00146 # define LPCWSTR LPCSTR
00147 
00148 // button check state for WIN16
00149 #ifndef BST_UNCHECKED
00150 #define BST_UNCHECKED      0x0000
00151 #endif
00152 
00153 #ifndef BST_CHECKED
00154 #define BST_CHECKED        0x0001
00155 #endif
00156 
00157 
00158 #ifndef WIN95_COMPAT
00159 #  define WIN95_COMPAT
00160 #endif
00161 
00162 // ~~MRJ end Win95 compat section.
00163 
00164 // critical section API stubs
00165 typedef DWORD CRITICAL_SECTION;
00166 typedef CRITICAL_SECTION FAR * LPCRITICAL_SECTION; 
00167 #ifdef __cplusplus
00168 inline void InitializeCriticalSection(LPCRITICAL_SECTION lpSection) {}
00169 inline void DeleteCriticalSection(LPCRITICAL_SECTION lpSection) {}
00170 inline void EnterCriticalSection(LPCRITICAL_SECTION lpSection) {}
00171 inline void LeaveCriticalSection(LPCRITICAL_SECTION lpSection) {} 
00172 #endif // __cplusplus 
00173 
00174 // Added for nssock16 ---Neeti
00175 #ifndef ZeroMemory
00176 #include <memory.h>
00177 #define ZeroMemory(PTR, SIZE) memset(PTR, 0, SIZE)
00178 #endif // ZeroMemory
00179 
00180 #endif // WIN16
00181 
00182 /*
00183  * unix - windows compatibility stuff
00184  */
00185 typedef DWORD u_int32;
00186 typedef WORD  u_int16;
00187 typedef BYTE  u_int8;
00188 #ifdef WIN32
00189 typedef short int Bool16;
00190 #else  // WIN16
00191 typedef BOOL  Bool16;
00192 #endif // WIN16
00193 
00194 /*
00195  * Cross Platform Compatibility
00196  */
00197 #ifndef UNALIGNED
00198 # ifdef _M_ALPHA
00199 #  define UNALIGNED __unaligned
00200 # else  // !_M_ALPHA
00201 #  define UNALIGNED
00202 # endif // !_M_ALPHA
00203 #endif  // UNALIGNED
00204 
00205 //
00206 // RICHIE - for the Alpha port
00207 //
00208 #ifdef _M_ALPHA
00209 # undef pascal
00210 # undef PASCAL
00211 # if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
00212 #  define pascal __stdcall
00213 #  define PASCAL __stdcall
00214 # else
00215 #  define PASCAL
00216 # endif
00217 #endif
00218 
00219 
00220 /*
00221  * Useful Types
00222  */
00223 typedef char HUGE *HPSTR;
00224 typedef const char HUGE *HPCSTR;
00225 typedef unsigned char HUGE *HPBYTE;
00226 typedef WORD HUGE *HPWORD;
00227 typedef UINT FAR *LPUINT;
00228 typedef BOOL (CALLBACK *USERABORTPROC)();
00229 typedef BOOL (CALLBACK *PROGRESSPROC)(UINT uPos, UINT uRange);
00230 typedef int INT;   // ~~MRJ a function needed this defined.
00231 typedef MINMAXINFO FAR *LPMINMAXINFO; // ~~MRJ 
00232 
00233 //
00234 // stuff missing from windows.h
00235 //
00236 #ifndef MAKEWORD
00237 #define MAKEWORD(low, high)    ((WORD)(((BYTE)(low)) | (((WORD)((BYTE)(high))) << 8)))
00238 #endif // MAKEWORD
00239 
00240 #ifdef WIN32
00241 # ifndef hmemcpy
00242 #  define hmemcpy memcpy
00243 # endif // !defined(hmemcpy)
00244 # define _fmemset memset
00245 
00246 # include <malloc.h>
00247 
00248 #ifdef __cplusplus
00249 
00250 inline BOOL IsGDIObject(HGDIOBJ hObj) { return (hObj != 0); }
00251 inline void *_halloc(long num, unsigned int size) { return malloc(num * size); }
00252 inline void _hfree( void *memblock ) { free(memblock); } 
00253 /*
00254 inline BOOL IsInstance(HINSTANCE hInst) {
00255 # ifdef WIN32
00256     return (hInst != 0);
00257 # else // WIN16
00258     return (hInst > HINSTANCE_ERROR);
00259 # endif  
00260 }  
00261 */
00262 
00263 #endif // __cplusplus
00264 
00265   WINUSERAPI HANDLE WINAPI LoadImageA(HINSTANCE, LPCSTR, UINT, int, int, UINT);
00266 
00267 #endif // WIN32
00268 
00269 #ifdef __cplusplus 
00270 inline BOOL IsInstance(HINSTANCE hInst) {
00271 # ifdef WIN32
00272     return (hInst != 0);
00273 # else // WIN16
00274     return (hInst > HINSTANCE_ERROR);
00275 # endif  
00276 } 
00277 inline void SetWindowSmallIcon(HINSTANCE hInst, HWND hWnd, UINT uIconResourceId) {
00278 #ifdef WIN32
00279 # ifndef WM_SETICON
00280 #   define WM_SETICON 0x0080
00281 # endif  // WM_SETICON
00282 # ifndef IMAGE_ICON
00283 #   define IMAGE_ICON 1
00284 # endif
00285   assert(IsWindow(hWnd));
00286   HICON hIcon = (HICON)LoadImageA(hInst, MAKEINTRESOURCE(uIconResourceId), IMAGE_ICON,
00287     16, 16, 0);
00288   if(NULL != hIcon) {
00289     SendMessage(hWnd, WM_SETICON, FALSE, (LPARAM)hIcon);
00290   } else {
00291     HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(uIconResourceId));
00292     assert(hIcon != 0);
00293     SendMessage(hWnd, WM_SETICON, FALSE, (LPARAM)hIcon);
00294   }
00295 #endif // WIN32
00296 }
00297 #endif // __cplusplus
00298 
00299 #ifdef __cplusplus
00300 }
00301 #endif /* __cplusplus */
00302 
00303 #endif /* PORT_H */