Back to index

lightning-sunbird  0.9+nobinonly
nsGfxDefs.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Mozilla OS/2 libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * John Fairhurst, <john_fairhurst@iname.com>.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either of the GNU General Public License Version 2 or later (the "GPL"),
00025  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #ifndef _nsgfxdefs_h
00038 #define _nsgfxdefs_h
00039 
00040 // nsGfxDefs.h - common includes etc. for gfx library
00041 
00042 #include "nscore.h"
00043 
00044 #define INCL_PM
00045 #define INCL_DOS
00046 #define INCL_DOSERRORS
00047 #define INCL_DEV
00048 #include <os2.h>
00049 #include "prlog.h"
00050 #include "nsHashtable.h"
00051 
00052 #include <uconv.h> // XXX hack XXX
00053 
00054 #define COLOR_CUBE_SIZE 216
00055 
00056 void PMERROR(const char *str);
00057 
00058 // Wrapper code for all OS/2 system calls to check the return code for error condition in debug build.
00059 // Could be used like this:
00060 //
00061 //    HDC hdc = GFX (::GpiQueryDevice (ps), HDC_ERROR);
00062 //    GFX (::GpiAssociate (mPrintPS, 0), FALSE);
00063 //    return GFX (::GpiDestroyPS (mPrintPS), FALSE);
00064 
00065 #ifdef DEBUG
00066   extern void DEBUG_LogErr(long ReturnCode, const char* ErrorExpression,
00067                            const char* FileName, const char* FunctionName,
00068                            long LineNum);
00069 
00070   inline long CheckSuccess(long ReturnCode, long SuccessCode,
00071                            const char* ErrorExpression, const char* FileName,
00072                            const char* FunctionName, long LineNum)
00073   {
00074     if (ReturnCode != SuccessCode) {
00075       DEBUG_LogErr(ReturnCode, ErrorExpression, FileName, FunctionName, LineNum);
00076     }
00077     return ReturnCode;
00078   }
00079 
00080   #define CHK_SUCCESS(ReturnCode, SuccessCode)                          \
00081           CheckSuccess(ReturnCode, SuccessCode, #ReturnCode, __FILE__,  \
00082                        __FUNCTION__, __LINE__)
00083 
00084   inline long CheckFailure(long ReturnCode, long ErrorCode,
00085                            const char* ErrorExpression, const char* FileName,
00086                            const char* FunctionName, long LineNum)
00087   {
00088     if (ReturnCode == ErrorCode) {
00089       DEBUG_LogErr(ReturnCode, ErrorExpression, FileName, FunctionName, LineNum);
00090     }
00091     return ReturnCode;
00092   }
00093 
00094 /*  #define CHK_FAIL(ReturnCode, ErrorCode)                             \ */
00095   #define GFX(ReturnCode, ErrorCode)                                  \
00096           CheckFailure(ReturnCode, ErrorCode, #ReturnCode, __FILE__,  \
00097                        __FUNCTION__, __LINE__)
00098 
00099 #else  // Retail build
00100   #define CHK_SUCCESS(ReturnCode, SuccessCode) ReturnCode
00101 /*  #define CHK_FAIL(ReturnCode, ErrorCode) ReturnCode */
00102   #define GFX(ReturnCode, ErrorCode) ReturnCode
00103 #endif
00104 
00105 class nsString;
00106 class nsIDeviceContext;
00107 
00108 
00109 BOOL GetTextExtentPoint32(HPS aPS, const char* aString, int aLength, PSIZEL aSizeL);
00110 BOOL ExtTextOut(HPS aPS, int X, int Y, UINT fuOptions, const RECTL* lprc,
00111                 const char* aString, unsigned int aLength, const int* pDx);
00112 
00113 BOOL IsDBCS();
00114 
00115 #ifndef min
00116 #define min(a,b) (((a) < (b)) ? (a) : (b))
00117 #endif
00118 
00119 #define MK_RGB(r,g,b) ((r) * 65536) + ((g) * 256) + (b)
00120 
00121 #ifdef DEBUG
00122 extern PRLogModuleInfo *gGFXOS2LogModule;
00123 #endif
00124 
00125 #endif