Changes for OS/2. Patch provided by Eric Olson (eric.olson@sympatico.ca)
git-svn-id: svn://10.0.0.236/trunk@234041 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
c2f3485a52
commit
beb820cdae
86
mozilla/widget/src/os2/nsGfxDefs.h
Normal file
86
mozilla/widget/src/os2/nsGfxDefs.h
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla OS/2 libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is John Fairhurst,
|
||||
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
|
||||
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _nsgfxdefs_h
|
||||
#define _nsgfxdefs_h
|
||||
|
||||
// nsGfxDefs.h - common includes etc. for gfx library
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#define INCL_PM
|
||||
#define INCL_DOS
|
||||
#include <os2.h>
|
||||
|
||||
#include <uconv.h> // XXX hack XXX
|
||||
|
||||
#define COLOR_CUBE_SIZE 216
|
||||
|
||||
void PMERROR(const char *str);
|
||||
|
||||
class nsString;
|
||||
class nsIPaletteOS2;
|
||||
class nsIDeviceContext;
|
||||
|
||||
// Module data
|
||||
struct nsGfxModuleData
|
||||
{
|
||||
HMODULE hModResources;
|
||||
HPS hpsScreen;
|
||||
LONG lDisplayDepth;
|
||||
|
||||
nsGfxModuleData();
|
||||
~nsGfxModuleData();
|
||||
|
||||
// XXX XXX XXX this is a hack copied from the widget library (where it's
|
||||
// not a hack but perfectly valid) until font-switching comes
|
||||
// on-line.
|
||||
// Unicode->local cp. conversions
|
||||
char *ConvertFromUcs( const PRUnichar *pText, ULONG ulLength, char *szBuffer, ULONG ulSize);
|
||||
char *ConvertFromUcs( const nsString &aStr, char *szBuffer, ULONG ulSize);
|
||||
// these methods use a single static buffer
|
||||
const char *ConvertFromUcs( const PRUnichar *pText, ULONG ulLength);
|
||||
const char *ConvertFromUcs( const nsString &aStr);
|
||||
|
||||
UconvObject converter;
|
||||
BOOL supplantConverter;
|
||||
PRUint32 renderingHints;
|
||||
ULONG ulCodepage;
|
||||
// XXX XXX XXX end hack
|
||||
|
||||
void Init();
|
||||
|
||||
// This addref's
|
||||
nsIPaletteOS2 *GetUIPalette( nsIDeviceContext *aContext);
|
||||
|
||||
protected:
|
||||
nsIPaletteOS2 *uiPalette;
|
||||
};
|
||||
|
||||
extern nsGfxModuleData gModuleData;
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#define MK_RGB(r,g,b) ((r) * 65536) + ((g) * 256) + (b)
|
||||
|
||||
#endif
|
||||
262
mozilla/widget/src/os2/nsPaletteOS2.cpp
Normal file
262
mozilla/widget/src/os2/nsPaletteOS2.cpp
Normal file
@ -0,0 +1,262 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla OS/2 libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is John Fairhurst,
|
||||
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
|
||||
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*/
|
||||
|
||||
// ToDo: nothing
|
||||
#include "nsGfxDefs.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "nsDeviceContextOS2.h" // sigh...
|
||||
#include "nsPaletteOS2.h"
|
||||
#include "il_util.h"
|
||||
|
||||
// os2fe/palette.cpp lives! Sort of.
|
||||
//
|
||||
// There's just the one palette, which is shared by all the windows,
|
||||
// DC's and whatever that get created.
|
||||
//
|
||||
// This makes apprunner vaguely usable!
|
||||
//
|
||||
// Printing might need some work.
|
||||
|
||||
// Common base
|
||||
class nsPaletteOS2 : public nsIPaletteOS2
|
||||
{
|
||||
protected:
|
||||
nsIDeviceContext *mContext; // don't hold a ref to avoid circularity
|
||||
PRUint8 *mGammaTable;
|
||||
|
||||
public:
|
||||
virtual nsresult Init( nsIDeviceContext *aContext,
|
||||
ULONG * = 0, ULONG = 0)
|
||||
{
|
||||
mContext = aContext;
|
||||
mContext->GetGammaTable( mGammaTable);
|
||||
return mContext == nsnull ? NS_ERROR_FAILURE : NS_OK;
|
||||
}
|
||||
|
||||
long GetGPIColor( HPS hps, nscolor rgb)
|
||||
{
|
||||
long gcolor = MK_RGB( mGammaTable[NS_GET_R(rgb)],
|
||||
mGammaTable[NS_GET_G(rgb)],
|
||||
mGammaTable[NS_GET_B(rgb)]);
|
||||
return GpiQueryColorIndex( hps, 0, gcolor);
|
||||
}
|
||||
|
||||
virtual nsresult GetNSPalette( nsPalette &aPalette) const
|
||||
{
|
||||
aPalette = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsPaletteOS2()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mContext = nsnull;
|
||||
mGammaTable = 0;
|
||||
}
|
||||
|
||||
virtual ~nsPaletteOS2()
|
||||
{}
|
||||
};
|
||||
|
||||
// this isn't really an xpcom object, so don't allow anyone to get anything
|
||||
nsresult nsPaletteOS2::QueryInterface( const nsIID&, void**)
|
||||
{
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsPaletteOS2)
|
||||
NS_IMPL_RELEASE(nsPaletteOS2)
|
||||
|
||||
// Logical colour table, for 8bpp with no palette manager or explicit choice
|
||||
class nsLCOLPaletteOS2 : public nsPaletteOS2
|
||||
{
|
||||
ULONG *mTable;
|
||||
ULONG mSize;
|
||||
|
||||
public:
|
||||
nsresult Init( nsIDeviceContext *aContext,
|
||||
ULONG *pEntries, ULONG cEntries)
|
||||
{
|
||||
mTable = pEntries;
|
||||
mSize = cEntries;
|
||||
return nsPaletteOS2::Init( aContext);
|
||||
}
|
||||
|
||||
nsresult Select( HPS hps, nsIDeviceContext *)
|
||||
{
|
||||
BOOL rc = GpiCreateLogColorTable( hps, LCOL_RESET | LCOL_PURECOLOR,
|
||||
LCOLF_CONSECRGB, 0,
|
||||
mSize, (PLONG) mTable);
|
||||
if( !rc)
|
||||
PMERROR( "GpiCreateLogColorTable");
|
||||
return rc ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult Deselect( HPS hps)
|
||||
{
|
||||
BOOL rc = GpiCreateLogColorTable( hps, LCOL_RESET, 0, 0, 0, 0);
|
||||
return rc ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsLCOLPaletteOS2()
|
||||
{
|
||||
mTable = 0;
|
||||
mSize = 0;
|
||||
}
|
||||
|
||||
~nsLCOLPaletteOS2()
|
||||
{
|
||||
if( mTable) free( mTable);
|
||||
}
|
||||
};
|
||||
|
||||
// Palette manager palette, for 8bpp with palette manager
|
||||
class nsHPALPaletteOS2 : public nsPaletteOS2
|
||||
{
|
||||
HPAL mHPal;
|
||||
|
||||
public:
|
||||
nsresult Init( nsIDeviceContext *aContext,
|
||||
ULONG *pEntries, ULONG cEntries)
|
||||
{
|
||||
mHPal = GpiCreatePalette( 0/*hab*/, LCOL_PURECOLOR, LCOLF_CONSECRGB,
|
||||
cEntries, pEntries);
|
||||
free( pEntries);
|
||||
|
||||
return nsPaletteOS2::Init( aContext);
|
||||
}
|
||||
|
||||
nsresult GetNSPalette( nsPalette &aPalette) const
|
||||
{
|
||||
aPalette = (nsPalette) mHPal;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult Select( HPS hps, nsIDeviceContext *aContext)
|
||||
{
|
||||
HPAL rc = GpiSelectPalette( hps, mHPal);
|
||||
if( rc == (HPAL) PAL_ERROR)
|
||||
{
|
||||
PMERROR( "GpiSelectPalette");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// okay, we could do with a window here. Unfortunately there's
|
||||
// no guarantee that this is going to return anything sensible.
|
||||
nsNativeWidget wdg = ((nsDeviceContextOS2 *) aContext)->mWidget;
|
||||
if( wdg)
|
||||
{
|
||||
ULONG ulDummy = 0;
|
||||
WinRealizePalette( (HWND)wdg, hps, &ulDummy);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult Deselect( HPS hps)
|
||||
{
|
||||
HPAL rc = GpiSelectPalette( hps, 0);
|
||||
return rc == ((HPAL)PAL_ERROR) ? NS_ERROR_FAILURE : NS_OK;
|
||||
}
|
||||
|
||||
nsHPALPaletteOS2()
|
||||
{
|
||||
mHPal = 0;
|
||||
}
|
||||
|
||||
~nsHPALPaletteOS2()
|
||||
{
|
||||
if( mHPal)
|
||||
GpiDeletePalette( mHPal);
|
||||
}
|
||||
};
|
||||
|
||||
// RGB colour table, for >8bpp
|
||||
class nsRGBPaletteOS2 : public nsPaletteOS2
|
||||
{
|
||||
public:
|
||||
nsresult Select( HPS hps, nsIDeviceContext *)
|
||||
{
|
||||
BOOL rc = GpiCreateLogColorTable( hps, LCOL_PURECOLOR,
|
||||
LCOLF_RGB, 0, 0, 0);
|
||||
if( !rc)
|
||||
PMERROR( "GpiCreateLogColorTable #2");
|
||||
return rc ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult Deselect( HPS hps)
|
||||
{
|
||||
BOOL rc = GpiCreateLogColorTable( hps, LCOL_RESET, 0, 0, 0, 0);
|
||||
return rc ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsRGBPaletteOS2() {}
|
||||
~nsRGBPaletteOS2() {}
|
||||
};
|
||||
|
||||
nsresult NS_CreatePalette( nsIDeviceContext *aContext, nsIPaletteOS2 *&aPalette)
|
||||
{
|
||||
nsresult rc = NS_OK;
|
||||
IL_ColorSpace *colorSpace = 0;
|
||||
|
||||
nsPaletteOS2 *newPalette = 0;
|
||||
|
||||
rc = aContext->GetILColorSpace( colorSpace);
|
||||
if( NS_SUCCEEDED(rc))
|
||||
{
|
||||
if( NI_PseudoColor == colorSpace->type)
|
||||
{
|
||||
PULONG pPalette = (PULONG) calloc( COLOR_CUBE_SIZE, sizeof( ULONG));
|
||||
|
||||
// Now set the color cube entries.
|
||||
for( PRInt32 i = 0; i < COLOR_CUBE_SIZE; i++)
|
||||
{
|
||||
IL_RGB *map = colorSpace->cmap.map + i;
|
||||
pPalette[ i] = MK_RGB( map->red, map->green, map->blue);
|
||||
}
|
||||
|
||||
// this works, sorta. Should probably tell users,
|
||||
// or activate via a pref, or something.
|
||||
if( getenv( "MOZ_USE_LCOL"))
|
||||
newPalette = new nsLCOLPaletteOS2;
|
||||
else
|
||||
newPalette = new nsHPALPaletteOS2;
|
||||
rc = newPalette->Init( aContext, pPalette, COLOR_CUBE_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
newPalette = new nsRGBPaletteOS2;
|
||||
rc = newPalette->Init( aContext);
|
||||
}
|
||||
|
||||
IL_ReleaseColorSpace( colorSpace);
|
||||
}
|
||||
|
||||
if( NS_SUCCEEDED(rc))
|
||||
{
|
||||
NS_ADDREF(newPalette);
|
||||
aPalette = newPalette;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
53
mozilla/widget/src/os2/nsPaletteOS2.h
Normal file
53
mozilla/widget/src/os2/nsPaletteOS2.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla OS/2 libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is John Fairhurst,
|
||||
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
|
||||
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*/
|
||||
|
||||
// Manage picking of colours via various GPI methods.
|
||||
// Created & (hopefully) destroyed by nsDeviceContextOS2; each rendering
|
||||
// context spun off from that dc holds a ref to it, and uses it to get things
|
||||
// right. Gamma correction done here too using the dc's table, so don't
|
||||
// go through gamma before GetGPIColor()'ing.
|
||||
//
|
||||
// !! What to do about A-channel ?
|
||||
|
||||
#ifndef _nspaletteos2_h
|
||||
#define _nspaletteos2_h
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nscolor.h"
|
||||
|
||||
class nsIDeviceContext;
|
||||
|
||||
class nsIPaletteOS2 : public nsISupports
|
||||
{
|
||||
public:
|
||||
virtual long GetGPIColor( HPS hps, nscolor rgb) = 0;
|
||||
virtual nsresult Select( HPS hps, nsIDeviceContext *aContext) = 0;
|
||||
virtual nsresult Deselect( HPS hps) = 0;
|
||||
virtual nsresult GetNSPalette( nsPalette &aPalette) const = 0;
|
||||
};
|
||||
|
||||
// So yes, this could be an nsDeviceContextOS2 method, but this way is better
|
||||
// for modularisation. Oh yes.
|
||||
// Release when done.
|
||||
nsresult NS_CreatePalette( nsIDeviceContext *aContext,
|
||||
nsIPaletteOS2 *&aPalette);
|
||||
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user