Back to index

lightning-sunbird  0.9+nobinonly
nsGfxDefs.cpp
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 #include "nsGfxDefs.h"
00038 
00039 #ifdef DEBUG
00040   #include <string.h>
00041   #include <ctype.h>
00042 
00043 //DJ  #include "nsLog.h"
00044 //DJ  NS_IMPL_LOG_ENABLED (GFXLog)
00045 //DJ  #define DPRINTF NS_LOG_PRINTF(GFXLog)
00046   #include <stdio.h>
00047   #define DPRINTF printf
00048 #else
00049   #include <stdio.h>
00050   #define DPRINTF printf
00051 #endif
00052 
00053 #include "nsDeviceContextSpecOS2.h"
00054 
00055 #include <stdlib.h>
00056 
00057 BOOL GetTextExtentPoint32(HPS aPS, const char* aString, int aLength, PSIZEL aSizeL)
00058 {
00059   BOOL rc = TRUE;
00060   POINTL ptls[5];
00061 
00062   aSizeL->cx = 0;
00063 
00064   while(aLength > 0 && rc == TRUE) {
00065     ULONG thislen = min(aLength, 512);
00066     rc = GFX (::GpiQueryTextBox(aPS, thislen, (PCH)aString, 5, ptls), FALSE);
00067     aSizeL->cx += ptls[TXTBOX_CONCAT].x;
00068     aLength -= thislen;
00069     aString += thislen;
00070   }
00071 
00072   aSizeL->cy = ptls[TXTBOX_TOPLEFT].y - ptls[TXTBOX_BOTTOMLEFT].y;
00073   return rc;
00074 }
00075 
00076 BOOL ExtTextOut(HPS aPS, int X, int Y, UINT fuOptions, const RECTL* lprc,
00077                 const char* aString, unsigned int aLength, const int* pSpacing)
00078 {
00079   long rc = GPI_OK;
00080   POINTL ptl = {X, Y};
00081 
00082   GFX (::GpiMove(aPS, &ptl), FALSE);
00083 
00084   // GpiCharString has a max length of 512 chars at a time...
00085   while (aLength > 0 && rc == GPI_OK) {
00086     ULONG ulChunkLen = min(aLength, 512);
00087     if (pSpacing) {
00088       rc = GFX (::GpiCharStringPos(aPS, nsnull, CHS_VECTOR, ulChunkLen,
00089                                    (PCH)aString, (PLONG)pSpacing), GPI_ERROR);
00090       pSpacing += ulChunkLen;
00091     } else {
00092       rc = GFX (::GpiCharString(aPS, ulChunkLen, (PCH)aString), GPI_ERROR);
00093     }
00094     aLength -= ulChunkLen;
00095     aString += ulChunkLen;
00096   }
00097 
00098   if (rc == GPI_OK)
00099     return TRUE;
00100   else
00101     return FALSE;
00102 }
00103 
00104 static BOOL bIsDBCS;
00105 static BOOL bIsDBCSSet = FALSE;
00106 
00107 BOOL IsDBCS()
00108 {
00109   if (!bIsDBCSSet) {
00110     // the following lines of code determine whether the system is a DBCS country
00111     APIRET rc;
00112     COUNTRYCODE ctrycodeInfo = {0};
00113     CHAR        achDBCSInfo[12] = {0};                  // DBCS environmental vector
00114     ctrycodeInfo.country  = 0;                          // current country
00115     ctrycodeInfo.codepage = 0;                          // current codepage
00116 
00117     rc = DosQueryDBCSEnv(sizeof(achDBCSInfo), &ctrycodeInfo, achDBCSInfo);
00118     if (rc == NO_ERROR)
00119     {
00120         // NON-DBCS countries will have four bytes in the first four bytes of the
00121         // DBCS environmental vector
00122         if (achDBCSInfo[0] != 0 || achDBCSInfo[1] != 0 ||
00123             achDBCSInfo[2] != 0 || achDBCSInfo[3] != 0)
00124         {
00125            bIsDBCS = TRUE;
00126         }
00127         else
00128         {
00129            bIsDBCS = FALSE;
00130         }
00131     } else {
00132        bIsDBCS = FALSE;
00133     } /* endif */
00134     bIsDBCSSet = TRUE;
00135   } /* endif */
00136   return bIsDBCS;
00137 }
00138 
00139 
00140 
00141 
00142 // Module-level data ---------------------------------------------------------
00143 #ifdef DEBUG
00144 void DEBUG_LogErr(long ReturnCode, const char* ErrorExpression,
00145                   const char* FileName, const char* FunctionName, long LineNum)
00146 {
00147    char TempBuf [300];
00148 
00149    strcpy (TempBuf, ErrorExpression);
00150    char* APIName = TempBuf;
00151 
00152    char* ch = strstr (APIName , "(");                 // Find start of function parameter list
00153    if (ch != NULL)                                    // Opening parenthesis found - it is a function
00154    {
00155       while (isspace (*--ch)) {}                      // Remove whitespaces before opening parenthesis
00156       *++ch = '\0';
00157 
00158       if (APIName [0] == ':' && APIName [1] == ':')   // Remove global scope operator
00159          APIName += 2;
00160 
00161       while (isspace (*APIName))                      // Remove spaces before function name
00162          APIName++;
00163    }
00164 
00165 
00166    USHORT ErrorCode = ERRORIDERROR (::WinGetLastError(0));
00167 
00168    printf("GFX_Err: %s = 0x%X, 0x%X (%s - %s,  line %ld)\n", APIName, ReturnCode,
00169           ErrorCode, FileName, FunctionName, LineNum);
00170 }
00171 #endif
00172 
00173 void PMERROR( const char *api)
00174 {
00175    ERRORID eid = ::WinGetLastError(0);
00176    USHORT usError = ERRORIDERROR(eid);
00177    DPRINTF ( "%s failed, error = 0x%X\n", api, usError);
00178 }
00179