OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [mwin/] [wingdi.c] - Diff between revs 27 and 174

Only display areas with differences | Details | Blame | View Log

Rev 27 Rev 174
/*
/*
 * Copyright (c) 1999, 2000, 2001 Greg Haerr <greg@censoft.com>
 * Copyright (c) 1999, 2000, 2001 Greg Haerr <greg@censoft.com>
 *
 *
 * Win32 API upper level graphics drawing routines
 * Win32 API upper level graphics drawing routines
 */
 */
#include "windows.h"
#include "windows.h"
#include "wintern.h"
#include "wintern.h"
#include "device.h"
#include "device.h"
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
 
 
#define MAXSYSCOLORS    29      /* # of COLOR_* system colors*/
#define MAXSYSCOLORS    29      /* # of COLOR_* system colors*/
#define MAXSTOCKOBJECTS 18      /* # of stock objects*/
#define MAXSTOCKOBJECTS 18      /* # of stock objects*/
 
 
#if ERASEMOVE
#if ERASEMOVE
BOOL mwERASEMOVE = TRUE;        /* default XORMOVE repaint algorithm*/
BOOL mwERASEMOVE = TRUE;        /* default XORMOVE repaint algorithm*/
#else
#else
BOOL mwERASEMOVE = FALSE;       /* default ERASEMOVE repaint algorithm*/
BOOL mwERASEMOVE = FALSE;       /* default ERASEMOVE repaint algorithm*/
#endif
#endif
 
 
/* cast a pointer to an integer*/
/* cast a pointer to an integer*/
#if DOS_TURBOC
#if DOS_TURBOC
#define PTRTOINT        unsigned long
#define PTRTOINT        unsigned long
#else
#else
#define PTRTOINT        unsigned int
#define PTRTOINT        unsigned int
#endif
#endif
 
 
static HDC      cliphdc;        /* current window cliprects*/
static HDC      cliphdc;        /* current window cliprects*/
 
 
/* default bitmap for new DCs*/
/* default bitmap for new DCs*/
static MWBITMAPOBJ default_bitmap = {
static MWBITMAPOBJ default_bitmap = {
        {OBJ_BITMAP, TRUE}, 1, 1, 1, 1, 1, 1
        {OBJ_BITMAP, TRUE}, 1, 1, 1, 1, 1, 1
};
};
 
 
static BOOL MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions,
static BOOL MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions,
                CONST RECT *lprc, LPCVOID lpszString, UINT cbCount,
                CONST RECT *lprc, LPCVOID lpszString, UINT cbCount,
                CONST INT *lpDx, int flags);
                CONST INT *lpDx, int flags);
static int  MwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect,
static int  MwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect,
                UINT uFormat, int flags);
                UINT uFormat, int flags);
 
 
HDC WINAPI
HDC WINAPI
GetDCEx(HWND hwnd,HRGN hrgnClip,DWORD flags)
GetDCEx(HWND hwnd,HRGN hrgnClip,DWORD flags)
{
{
        HDC     hdc;
        HDC     hdc;
 
 
        if(!hwnd)               /* handle NULL hwnd => desktop*/
        if(!hwnd)               /* handle NULL hwnd => desktop*/
                hwnd = rootwp;
                hwnd = rootwp;
 
 
        /* handle private DC's*/
        /* handle private DC's*/
        if(hwnd->owndc && !(flags & DCX_WINDOW))
        if(hwnd->owndc && !(flags & DCX_WINDOW))
                return hwnd->owndc;
                return hwnd->owndc;
 
 
        /* add caching?*/
        /* add caching?*/
        hdc = GdItemNew(struct hdc);
        hdc = GdItemNew(struct hdc);
        if(!hdc)
        if(!hdc)
                return NULL;
                return NULL;
 
 
        hdc->psd = &scrdev;
        hdc->psd = &scrdev;
        hdc->hwnd = hwnd;
        hdc->hwnd = hwnd;
        if(flags & DCX_DEFAULTCLIP) {
        if(flags & DCX_DEFAULTCLIP) {
                flags &= ~DCX_DEFAULTCLIP;
                flags &= ~DCX_DEFAULTCLIP;
                if(hwnd->style & WS_CLIPSIBLINGS)
                if(hwnd->style & WS_CLIPSIBLINGS)
                        flags |= DCX_CLIPSIBLINGS;
                        flags |= DCX_CLIPSIBLINGS;
                if(hwnd->style & WS_CLIPCHILDREN)
                if(hwnd->style & WS_CLIPCHILDREN)
                        flags |= DCX_CLIPCHILDREN;
                        flags |= DCX_CLIPCHILDREN;
        }
        }
        hdc->flags = flags;
        hdc->flags = flags;
        hdc->bkmode = OPAQUE;
        hdc->bkmode = OPAQUE;
        hdc->textalign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
        hdc->textalign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
        hdc->bkcolor = RGB(255, 255, 255);      /* WHITE*/
        hdc->bkcolor = RGB(255, 255, 255);      /* WHITE*/
        hdc->textcolor = RGB(0, 0, 0);             /* BLACK*/
        hdc->textcolor = RGB(0, 0, 0);             /* BLACK*/
        hdc->brush = (MWBRUSHOBJ *)GetStockObject(WHITE_BRUSH);
        hdc->brush = (MWBRUSHOBJ *)GetStockObject(WHITE_BRUSH);
        hdc->pen = (MWPENOBJ *)GetStockObject(BLACK_PEN);
        hdc->pen = (MWPENOBJ *)GetStockObject(BLACK_PEN);
        hdc->font = (MWFONTOBJ *)GetStockObject(SYSTEM_FONT);
        hdc->font = (MWFONTOBJ *)GetStockObject(SYSTEM_FONT);
#if UPDATEREGIONS
#if UPDATEREGIONS
        if(hrgnClip) {
        if(hrgnClip) {
                /* make a copy of passed region*/
                /* make a copy of passed region*/
                hdc->region = (MWRGNOBJ *)CreateRectRgn(0, 0, 0, 0);
                hdc->region = (MWRGNOBJ *)CreateRectRgn(0, 0, 0, 0);
                CombineRgn((HRGN)hdc->region, hrgnClip, NULL, RGN_COPY);
                CombineRgn((HRGN)hdc->region, hrgnClip, NULL, RGN_COPY);
        }
        }
#endif
#endif
 
 
        /* make default bitmap compatible with scrdev
        /* make default bitmap compatible with scrdev
         * otherwise problems occur later because selecting
         * otherwise problems occur later because selecting
         * in the default bitmap overwrite planes and bpp
         * in the default bitmap overwrite planes and bpp
         * in a memory dc, and thus it becomes incompatible
         * in a memory dc, and thus it becomes incompatible
         * with scrdev.
         * with scrdev.
         */
         */
        default_bitmap.planes = scrdev.planes;
        default_bitmap.planes = scrdev.planes;
        default_bitmap.bpp = scrdev.bpp;
        default_bitmap.bpp = scrdev.bpp;
        hdc->bitmap = &default_bitmap;
        hdc->bitmap = &default_bitmap;
 
 
        hdc->drawmode = R2_COPYPEN;
        hdc->drawmode = R2_COPYPEN;
        hdc->pt.x = 0;
        hdc->pt.x = 0;
        hdc->pt.y = 0;
        hdc->pt.y = 0;
 
 
        /* assign private DC if CS_OWNDC and not WindowDC*/
        /* assign private DC if CS_OWNDC and not WindowDC*/
        if((hwnd->pClass->style & CS_OWNDC) && !(flags & DCX_WINDOW)) {
        if((hwnd->pClass->style & CS_OWNDC) && !(flags & DCX_WINDOW)) {
                /* must exclude update region due to BeginPaint GetDCEx call*/
                /* must exclude update region due to BeginPaint GetDCEx call*/
                hdc->flags |= DCX_EXCLUDEUPDATE;
                hdc->flags |= DCX_EXCLUDEUPDATE;
                hwnd->owndc = hdc;
                hwnd->owndc = hdc;
        }
        }
 
 
        return hdc;
        return hdc;
}
}
 
 
HDC WINAPI
HDC WINAPI
GetDC(HWND hwnd)
GetDC(HWND hwnd)
{
{
        /*
        /*
         * Exclude update regions when drawing with GetDC.
         * Exclude update regions when drawing with GetDC.
         * This is required because some programs use GetDC
         * This is required because some programs use GetDC
         * when painting outside of BeginPaint/EndPaint, and
         * when painting outside of BeginPaint/EndPaint, and
         * the update region is empty then.
         * the update region is empty then.
         */
         */
        return GetDCEx(hwnd, NULL, DCX_DEFAULTCLIP|DCX_EXCLUDEUPDATE);
        return GetDCEx(hwnd, NULL, DCX_DEFAULTCLIP|DCX_EXCLUDEUPDATE);
}
}
 
 
HDC WINAPI
HDC WINAPI
GetWindowDC(HWND hwnd)
GetWindowDC(HWND hwnd)
{
{
        /*
        /*
         * Exclude update region for now, since we
         * Exclude update region for now, since we
         * don't keep track of non-client update regions yet
         * don't keep track of non-client update regions yet
         */
         */
        return GetDCEx(hwnd, NULL,DCX_WINDOW|DCX_DEFAULTCLIP|DCX_EXCLUDEUPDATE);
        return GetDCEx(hwnd, NULL,DCX_WINDOW|DCX_DEFAULTCLIP|DCX_EXCLUDEUPDATE);
}
}
 
 
/* free a DC allocated from GetDC*/
/* free a DC allocated from GetDC*/
int WINAPI
int WINAPI
ReleaseDC(HWND hwnd, HDC hdc)
ReleaseDC(HWND hwnd, HDC hdc)
{
{
        /* don't delete a memory dc on release*/
        /* don't delete a memory dc on release*/
        if(!hdc || (hdc->psd->flags&PSF_MEMORY))
        if(!hdc || (hdc->psd->flags&PSF_MEMORY))
                return 0;
                return 0;
 
 
        if(hdc == cliphdc)
        if(hdc == cliphdc)
                cliphdc = NULL;
                cliphdc = NULL;
 
 
        /* handle private DC's*/
        /* handle private DC's*/
        if(hdc->hwnd->owndc && !(hdc->flags & DCX_WINDOW))
        if(hdc->hwnd->owndc && !(hdc->flags & DCX_WINDOW))
                return 1;
                return 1;
 
 
        DeleteObject((HBRUSH)hdc->brush);
        DeleteObject((HBRUSH)hdc->brush);
        DeleteObject((HPEN)hdc->pen);
        DeleteObject((HPEN)hdc->pen);
#if 0 /* don't delete font resources on ReleaseDC... use DeleteObject instead*/
#if 0 /* don't delete font resources on ReleaseDC... use DeleteObject instead*/
        DeleteObject((HFONT)hdc->font);
        DeleteObject((HFONT)hdc->font);
#endif
#endif
        DeleteObject((HRGN)hdc->region);
        DeleteObject((HRGN)hdc->region);
        /*
        /*
         * We can only select a bitmap in a memory DC,
         * We can only select a bitmap in a memory DC,
         * so bitmaps aren't released except through DeleteDC.
         * so bitmaps aren't released except through DeleteDC.
         */
         */
        DeleteObject((HBITMAP)hdc->bitmap);
        DeleteObject((HBITMAP)hdc->bitmap);
        GdItemFree(hdc);
        GdItemFree(hdc);
        return 1;
        return 1;
}
}
 
 
/* free a dc allocated from CreateCompatibleDC*/
/* free a dc allocated from CreateCompatibleDC*/
BOOL WINAPI
BOOL WINAPI
DeleteDC(HDC hdc)
DeleteDC(HDC hdc)
{
{
        /* don't delete a normal dc, only memory dc's*/
        /* don't delete a normal dc, only memory dc's*/
        if(!hdc || !(hdc->psd->flags&PSF_MEMORY))
        if(!hdc || !(hdc->psd->flags&PSF_MEMORY))
                return 0;
                return 0;
 
 
        /* free allocated memory screen device*/
        /* free allocated memory screen device*/
        hdc->psd->FreeMemGC(hdc->psd);
        hdc->psd->FreeMemGC(hdc->psd);
 
 
        /* make it look like a GetDC dc, and free it*/
        /* make it look like a GetDC dc, and free it*/
        hdc->psd = &scrdev;
        hdc->psd = &scrdev;
        return ReleaseDC(NULL, hdc);
        return ReleaseDC(NULL, hdc);
}
}
 
 
void
void
MwPaintNCArea(HWND hwnd)
MwPaintNCArea(HWND hwnd)
{
{
        SendMessage(hwnd, WM_NCPAINT, 0, 0L);
        SendMessage(hwnd, WM_NCPAINT, 0, 0L);
 
 
        /* for now, we always paint NC scrollbar areas*/
        /* for now, we always paint NC scrollbar areas*/
        MwPaintNCScrollbars(hwnd, NULL);
        MwPaintNCScrollbars(hwnd, NULL);
}
}
 
 
HDC WINAPI
HDC WINAPI
BeginPaint(HWND hwnd, LPPAINTSTRUCT lpPaint)
BeginPaint(HWND hwnd, LPPAINTSTRUCT lpPaint)
{
{
        HDC     hdc;
        HDC     hdc;
 
 
        /* first update non-client area*/
        /* first update non-client area*/
        if(mwforceNCpaint || hwnd->paintNC != mwpaintNC) {
        if(mwforceNCpaint || hwnd->paintNC != mwpaintNC) {
                MwPaintNCArea(hwnd);
                MwPaintNCArea(hwnd);
                hwnd->paintNC = mwpaintNC;
                hwnd->paintNC = mwpaintNC;
        }
        }
 
 
        /* If ERASEMOVE:
        /* If ERASEMOVE:
         * Don't allow windows to repaint while user is moving
         * Don't allow windows to repaint while user is moving
         * a window.  Instead, just erase backgrounds
         * a window.  Instead, just erase backgrounds
         * and indicate delayed painting required, which
         * and indicate delayed painting required, which
         * will occur after user completes window move.
         * will occur after user completes window move.
         */
         */
        if(mwERASEMOVE && dragwp) {
        if(mwERASEMOVE && dragwp) {
                hdc = NULL;
                hdc = NULL;
                lpPaint->fErase = !DefWindowProc(hwnd, WM_ERASEBKGND, 0, 0L);
                lpPaint->fErase = !DefWindowProc(hwnd, WM_ERASEBKGND, 0, 0L);
                hwnd->gotPaintMsg = PAINT_DELAYPAINT;
                hwnd->gotPaintMsg = PAINT_DELAYPAINT;
        } else {
        } else {
                HideCaret(hwnd);
                HideCaret(hwnd);
 
 
                /* FIXME: mdemo requires update excluded or draw errors occur*/
                /* FIXME: mdemo requires update excluded or draw errors occur*/
                hdc = GetDCEx(hwnd, NULL, DCX_DEFAULTCLIP
                hdc = GetDCEx(hwnd, NULL, DCX_DEFAULTCLIP
                                |DCX_EXCLUDEUPDATE);    /* FIXME - bug*/
                                |DCX_EXCLUDEUPDATE);    /* FIXME - bug*/
 
 
                /* erase client background*/
                /* erase client background*/
                lpPaint->fErase = !SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc,
                lpPaint->fErase = !SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc,
                        0L);
                        0L);
        }
        }
        lpPaint->hdc = hdc;
        lpPaint->hdc = hdc;
 
 
        GetUpdateRect(hwnd, &lpPaint->rcPaint, FALSE);
        GetUpdateRect(hwnd, &lpPaint->rcPaint, FALSE);
        return hdc;
        return hdc;
}
}
 
 
BOOL WINAPI
BOOL WINAPI
EndPaint(HWND hwnd, CONST PAINTSTRUCT *lpPaint)
EndPaint(HWND hwnd, CONST PAINTSTRUCT *lpPaint)
{
{
        ReleaseDC(hwnd, lpPaint->hdc);
        ReleaseDC(hwnd, lpPaint->hdc);
#if UPDATEREGIONS
#if UPDATEREGIONS
        /* don't clear update region until done dragging*/
        /* don't clear update region until done dragging*/
        if(mwERASEMOVE && !dragwp)
        if(mwERASEMOVE && !dragwp)
                GdSetRectRegion(hwnd->update, 0, 0, 0, 0);
                GdSetRectRegion(hwnd->update, 0, 0, 0, 0);
#endif
#endif
        ShowCaret(hwnd);
        ShowCaret(hwnd);
        return TRUE;
        return TRUE;
}
}
 
 
COLORREF WINAPI
COLORREF WINAPI
SetTextColor(HDC hdc, COLORREF crColor)
SetTextColor(HDC hdc, COLORREF crColor)
{
{
        COLORREF        oldtextcolor;
        COLORREF        oldtextcolor;
 
 
        if (!hdc)
        if (!hdc)
                return CLR_INVALID;
                return CLR_INVALID;
        oldtextcolor = hdc->textcolor;
        oldtextcolor = hdc->textcolor;
        hdc->textcolor = (MWCOLORVAL)crColor;
        hdc->textcolor = (MWCOLORVAL)crColor;
        return oldtextcolor;
        return oldtextcolor;
}
}
 
 
COLORREF WINAPI
COLORREF WINAPI
SetBkColor(HDC hdc, COLORREF crColor)
SetBkColor(HDC hdc, COLORREF crColor)
{
{
        COLORREF        oldbkcolor;
        COLORREF        oldbkcolor;
 
 
        if (!hdc)
        if (!hdc)
                return CLR_INVALID;
                return CLR_INVALID;
        oldbkcolor = hdc->bkcolor;
        oldbkcolor = hdc->bkcolor;
        hdc->bkcolor = crColor;
        hdc->bkcolor = crColor;
        return oldbkcolor;
        return oldbkcolor;
}
}
 
 
int WINAPI
int WINAPI
SetBkMode(HDC hdc, int iBkMode)
SetBkMode(HDC hdc, int iBkMode)
{
{
        int     oldbkmode;
        int     oldbkmode;
 
 
        if(!hdc)
        if(!hdc)
                return 0;
                return 0;
        oldbkmode = hdc->bkmode;
        oldbkmode = hdc->bkmode;
        hdc->bkmode = iBkMode;
        hdc->bkmode = iBkMode;
        return oldbkmode;
        return oldbkmode;
}
}
 
 
UINT WINAPI
UINT WINAPI
SetTextAlign(HDC hdc, UINT fMode)
SetTextAlign(HDC hdc, UINT fMode)
{
{
        UINT    oldfMode;
        UINT    oldfMode;
 
 
        if(!hdc)
        if(!hdc)
                return GDI_ERROR;
                return GDI_ERROR;
        oldfMode = hdc->textalign;
        oldfMode = hdc->textalign;
        hdc->textalign = fMode;
        hdc->textalign = fMode;
        return oldfMode;
        return oldfMode;
}
}
 
 
/* FIXME: releasing a DC does NOT change back the drawing mode!*/
/* FIXME: releasing a DC does NOT change back the drawing mode!*/
int WINAPI
int WINAPI
SetROP2(HDC hdc, int fnDrawMode)
SetROP2(HDC hdc, int fnDrawMode)
{
{
        int     newmode, oldmode;
        int     newmode, oldmode;
 
 
        if(!hdc || (fnDrawMode <= 0 || fnDrawMode > R2_LAST))
        if(!hdc || (fnDrawMode <= 0 || fnDrawMode > R2_LAST))
                return 0;
                return 0;
 
 
        oldmode = hdc->drawmode;
        oldmode = hdc->drawmode;
        newmode = fnDrawMode - 1;       /* map to MWMODE_xxx*/
        newmode = fnDrawMode - 1;       /* map to MWMODE_xxx*/
        hdc->drawmode = newmode;
        hdc->drawmode = newmode;
        GdSetMode(newmode);
        GdSetMode(newmode);
        return oldmode;
        return oldmode;
}
}
 
 
/*
/*
 * Setup clip region from device context's associated window or bitmap.
 * Setup clip region from device context's associated window or bitmap.
 * Memory DC's are always associated with the desktop window, and are
 * Memory DC's are always associated with the desktop window, and are
 * always visible.  Return the DC's hwnd if window is visible.
 * always visible.  Return the DC's hwnd if window is visible.
 */
 */
HWND
HWND
MwPrepareDC(HDC hdc)
MwPrepareDC(HDC hdc)
{
{
        HWND    hwnd;
        HWND    hwnd;
 
 
        if(!hdc || !hdc->hwnd)
        if(!hdc || !hdc->hwnd)
                return NULL;
                return NULL;
 
 
        hwnd = hdc->hwnd;
        hwnd = hdc->hwnd;
        if (hwnd->unmapcount)
        if (hwnd->unmapcount)
                return NULL;
                return NULL;
 
 
        /*
        /*
         * If the window is not the currently clipped one, then
         * If the window is not the currently clipped one, then
         * make it the current one and define its clip rectangles.
         * make it the current one and define its clip rectangles.
         */
         */
        if(hdc != cliphdc) {
        if(hdc != cliphdc) {
                /* clip memory dc's to the bitmap size*/
                /* clip memory dc's to the bitmap size*/
                if(hdc->psd->flags&PSF_MEMORY) {
                if(hdc->psd->flags&PSF_MEMORY) {
#if DYNAMICREGIONS
#if DYNAMICREGIONS
                        GdSetClipRegion(hdc->psd,
                        GdSetClipRegion(hdc->psd,
                                GdAllocRectRegion(0, 0, hdc->psd->xvirtres,
                                GdAllocRectRegion(0, 0, hdc->psd->xvirtres,
                                        hdc->psd->yvirtres));
                                        hdc->psd->yvirtres));
#else
#else
                        static MWCLIPRECT crc = {0, 0, 0, 0};
                        static MWCLIPRECT crc = {0, 0, 0, 0};
 
 
                        crc.width = hdc->psd->xvirtres;
                        crc.width = hdc->psd->xvirtres;
                        crc.height = hdc->psd->yvirtres;
                        crc.height = hdc->psd->yvirtres;
                        GdSetClipRects(hdc->psd, 1, &crc);
                        GdSetClipRects(hdc->psd, 1, &crc);
#endif
#endif
                } else MwSetClipWindow(hdc);
                } else MwSetClipWindow(hdc);
                cliphdc = hdc;
                cliphdc = hdc;
        }
        }
 
 
        return hwnd;
        return hwnd;
}
}
 
 
/* return RGB value at specified coordinates*/
/* return RGB value at specified coordinates*/
COLORREF WINAPI
COLORREF WINAPI
GetPixel(HDC hdc, int x, int y)
GetPixel(HDC hdc, int x, int y)
{
{
        HWND            hwnd;
        HWND            hwnd;
        POINT           pt;
        POINT           pt;
        MWPIXELVAL      pixel;
        MWPIXELVAL      pixel;
        MWPALENTRY      rgb;
        MWPALENTRY      rgb;
 
 
        hwnd = MwPrepareDC(hdc);
        hwnd = MwPrepareDC(hdc);
        if(!hwnd)
        if(!hwnd)
                return CLR_INVALID;
                return CLR_INVALID;
        pt.x = x;
        pt.x = x;
        pt.y = y;
        pt.y = y;
        if(MwIsClientDC(hdc))
        if(MwIsClientDC(hdc))
                ClientToScreen(hwnd, &pt);
                ClientToScreen(hwnd, &pt);
 
 
        /* read pixel value*/
        /* read pixel value*/
        GdReadArea(hdc->psd, pt.x, pt.y, 1, 1, &pixel);
        GdReadArea(hdc->psd, pt.x, pt.y, 1, 1, &pixel);
 
 
        switch(hdc->psd->pixtype) {
        switch(hdc->psd->pixtype) {
        case MWPF_TRUECOLOR0888:
        case MWPF_TRUECOLOR0888:
        case MWPF_TRUECOLOR888:
        case MWPF_TRUECOLOR888:
                /* create RGB colorval from 8/8/8 pixel*/
                /* create RGB colorval from 8/8/8 pixel*/
                return PIXEL888TOCOLORVAL(pixel);
                return PIXEL888TOCOLORVAL(pixel);
 
 
        case MWPF_TRUECOLOR565:
        case MWPF_TRUECOLOR565:
                /* create RGB colorval from 5/6/5 pixel*/
                /* create RGB colorval from 5/6/5 pixel*/
                return PIXEL565TOCOLORVAL(pixel);
                return PIXEL565TOCOLORVAL(pixel);
 
 
        case MWPF_TRUECOLOR555:
        case MWPF_TRUECOLOR555:
                /* create RGB colorval from 5/5/5 pixel*/
                /* create RGB colorval from 5/5/5 pixel*/
                return PIXEL555TOCOLORVAL(pixel);
                return PIXEL555TOCOLORVAL(pixel);
 
 
        case MWPF_TRUECOLOR332:
        case MWPF_TRUECOLOR332:
                /* create RGB colorval from 3/3/2 pixel*/
                /* create RGB colorval from 3/3/2 pixel*/
                return PIXEL332TOCOLORVAL(pixel);
                return PIXEL332TOCOLORVAL(pixel);
 
 
        case MWPF_PALETTE:
        case MWPF_PALETTE:
                if(GdGetPalette(hdc->psd, pixel, 1, &rgb))
                if(GdGetPalette(hdc->psd, pixel, 1, &rgb))
                        return RGB(rgb.r, rgb.g, rgb.b);
                        return RGB(rgb.r, rgb.g, rgb.b);
        }
        }
        return CLR_INVALID;
        return CLR_INVALID;
}
}
 
 
COLORREF WINAPI
COLORREF WINAPI
SetPixel(HDC hdc, int x, int y, COLORREF crColor)
SetPixel(HDC hdc, int x, int y, COLORREF crColor)
{
{
        HWND            hwnd;
        HWND            hwnd;
        POINT           pt;
        POINT           pt;
 
 
        hwnd = MwPrepareDC(hdc);
        hwnd = MwPrepareDC(hdc);
        if(!hwnd)
        if(!hwnd)
                return 0;        /* doesn't return previous color*/
                return 0;        /* doesn't return previous color*/
        pt.x = x;
        pt.x = x;
        pt.y = y;
        pt.y = y;
        if(MwIsClientDC(hdc))
        if(MwIsClientDC(hdc))
                ClientToScreen(hwnd, &pt);
                ClientToScreen(hwnd, &pt);
 
 
        /* draw point in passed color*/
        /* draw point in passed color*/
        GdSetForeground(GdFindColor(crColor));
        GdSetForeground(GdFindColor(crColor));
        GdPoint(hdc->psd, pt.x, pt.y);
        GdPoint(hdc->psd, pt.x, pt.y);
        return 0;                /* doesn't return previous color*/
        return 0;                /* doesn't return previous color*/
}
}
 
 
BOOL WINAPI
BOOL WINAPI
MoveToEx(HDC hdc, int x, int y, LPPOINT lpPoint)
MoveToEx(HDC hdc, int x, int y, LPPOINT lpPoint)
{
{
        if(!hdc)
        if(!hdc)
                return FALSE;
                return FALSE;
        if(lpPoint)
        if(lpPoint)
                *lpPoint = hdc->pt;
                *lpPoint = hdc->pt;
        hdc->pt.x = x;
        hdc->pt.x = x;
        hdc->pt.y = y;
        hdc->pt.y = y;
        return TRUE;
        return TRUE;
}
}
 
 
BOOL WINAPI
BOOL WINAPI
LineTo(HDC hdc, int x, int y)
LineTo(HDC hdc, int x, int y)
{
{
        HWND            hwnd;
        HWND            hwnd;
        POINT           beg, end;
        POINT           beg, end;
 
 
        hwnd = MwPrepareDC(hdc);
        hwnd = MwPrepareDC(hdc);
        if(!hwnd)
        if(!hwnd)
                return FALSE;
                return FALSE;
 
 
        beg.x = hdc->pt.x;
        beg.x = hdc->pt.x;
        beg.y = hdc->pt.y;
        beg.y = hdc->pt.y;
        end.x = x;
        end.x = x;
        end.y = y;
        end.y = y;
        if(MwIsClientDC(hdc)) {
        if(MwIsClientDC(hdc)) {
                ClientToScreen(hwnd, &beg);
                ClientToScreen(hwnd, &beg);
                ClientToScreen(hwnd, &end);
                ClientToScreen(hwnd, &end);
        }
        }
 
 
        /* draw line in current pen color*/
        /* draw line in current pen color*/
        if(hdc->pen->style != PS_NULL) {
        if(hdc->pen->style != PS_NULL) {
                GdSetForeground(GdFindColor(hdc->pen->color));
                GdSetForeground(GdFindColor(hdc->pen->color));
                /* don't draw last point*/
                /* don't draw last point*/
                GdLine(hdc->psd, beg.x, beg.y, end.x, end.y, FALSE);
                GdLine(hdc->psd, beg.x, beg.y, end.x, end.y, FALSE);
        }
        }
        hdc->pt.x = x;
        hdc->pt.x = x;
        hdc->pt.y = y;
        hdc->pt.y = y;
        return TRUE;
        return TRUE;
}
}
 
 
/* draw line segments by connecting passed points*/
/* draw line segments by connecting passed points*/
BOOL WINAPI
BOOL WINAPI
Polyline(HDC hdc, CONST POINT *lppt, int cPoints)
Polyline(HDC hdc, CONST POINT *lppt, int cPoints)
{
{
        HWND            hwnd;
        HWND            hwnd;
        POINT           beg, end;
        POINT           beg, end;
 
 
        if(cPoints <= 1)
        if(cPoints <= 1)
                return FALSE;
                return FALSE;
 
 
        hwnd = MwPrepareDC(hdc);
        hwnd = MwPrepareDC(hdc);
        if(!hwnd)
        if(!hwnd)
                return FALSE;
                return FALSE;
 
 
        if(hdc->pen->style == PS_NULL)
        if(hdc->pen->style == PS_NULL)
                return TRUE;
                return TRUE;
 
 
        /* draw line in current pen color*/
        /* draw line in current pen color*/
        GdSetForeground(GdFindColor(hdc->pen->color));
        GdSetForeground(GdFindColor(hdc->pen->color));
 
 
        beg = *lppt++;
        beg = *lppt++;
        if(MwIsClientDC(hdc))
        if(MwIsClientDC(hdc))
                ClientToScreen(hwnd, &beg);
                ClientToScreen(hwnd, &beg);
        while(--cPoints > 0) {
        while(--cPoints > 0) {
                end = *lppt++;
                end = *lppt++;
                if(MwIsClientDC(hdc))
                if(MwIsClientDC(hdc))
                        ClientToScreen(hwnd, &end);
                        ClientToScreen(hwnd, &end);
 
 
                /* don't draw last point*/
                /* don't draw last point*/
                GdLine(hdc->psd, beg.x, beg.y, end.x, end.y, FALSE);
                GdLine(hdc->psd, beg.x, beg.y, end.x, end.y, FALSE);
 
 
                beg = end;
                beg = end;
        }
        }
        return TRUE;
        return TRUE;
}
}
 
 
BOOL WINAPI
BOOL WINAPI
Rectangle(HDC hdc, int nLeft, int nTop, int nRight, int nBottom)
Rectangle(HDC hdc, int nLeft, int nTop, int nRight, int nBottom)
{
{
        HWND    hwnd;
        HWND    hwnd;
        RECT    rc;
        RECT    rc;
 
 
        hwnd = MwPrepareDC(hdc);
        hwnd = MwPrepareDC(hdc);
        if(!hwnd)
        if(!hwnd)
                return FALSE;
                return FALSE;
 
 
        SetRect(&rc, nLeft, nTop, nRight, nBottom);
        SetRect(&rc, nLeft, nTop, nRight, nBottom);
        if(MwIsClientDC(hdc))
        if(MwIsClientDC(hdc))
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
 
 
        /* draw rectangle in current pen color*/
        /* draw rectangle in current pen color*/
        if(hdc->pen->style != PS_NULL) {
        if(hdc->pen->style != PS_NULL) {
                GdSetForeground(GdFindColor(hdc->pen->color));
                GdSetForeground(GdFindColor(hdc->pen->color));
                GdRect(hdc->psd, rc.left, rc.top,
                GdRect(hdc->psd, rc.left, rc.top,
                        rc.right - rc.left, rc.bottom - rc.top);
                        rc.right - rc.left, rc.bottom - rc.top);
        }
        }
 
 
        /* fill rectangle in current brush color*/
        /* fill rectangle in current brush color*/
        if(hdc->brush->style != BS_NULL) {
        if(hdc->brush->style != BS_NULL) {
                InflateRect(&rc, -1, -1);
                InflateRect(&rc, -1, -1);
                GdSetForeground(GdFindColor(hdc->brush->color));
                GdSetForeground(GdFindColor(hdc->brush->color));
                GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left,
                GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left,
                        rc.bottom - rc.top);
                        rc.bottom - rc.top);
        }
        }
 
 
        return TRUE;
        return TRUE;
}
}
 
 
BOOL WINAPI
BOOL WINAPI
Ellipse(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect)
Ellipse(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect)
{
{
        HWND    hwnd;
        HWND    hwnd;
        int     rx, ry;
        int     rx, ry;
        RECT    rc;
        RECT    rc;
 
 
        hwnd = MwPrepareDC(hdc);
        hwnd = MwPrepareDC(hdc);
        if(!hwnd)
        if(!hwnd)
                return FALSE;
                return FALSE;
 
 
        SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect);
        SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect);
        if(MwIsClientDC(hdc))
        if(MwIsClientDC(hdc))
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
 
 
        rx = (rc.right - rc.left)/2 - 1;
        rx = (rc.right - rc.left)/2 - 1;
        ry = (rc.bottom - rc.top)/2 - 1;
        ry = (rc.bottom - rc.top)/2 - 1;
        rc.left += rx;
        rc.left += rx;
        rc.top += ry;
        rc.top += ry;
 
 
        /* fill ellipse in current brush color*/
        /* fill ellipse in current brush color*/
        if(hdc->brush->style != BS_NULL) {
        if(hdc->brush->style != BS_NULL) {
                InflateRect(&rc, -1, -1);
                InflateRect(&rc, -1, -1);
                GdSetForeground(GdFindColor(hdc->brush->color));
                GdSetForeground(GdFindColor(hdc->brush->color));
                GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, TRUE);
                GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, TRUE);
        }
        }
 
 
        /* draw ellipse outline in current pen color*/
        /* draw ellipse outline in current pen color*/
        if(hdc->pen->style != PS_NULL) {
        if(hdc->pen->style != PS_NULL) {
                GdSetForeground(GdFindColor(hdc->pen->color));
                GdSetForeground(GdFindColor(hdc->pen->color));
                GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, FALSE);
                GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, FALSE);
        }
        }
 
 
        return TRUE;
        return TRUE;
}
}
 
 
static void
static void
dopiearc(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
dopiearc(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
        int ax, int ay, int bx, int by, int type)
        int ax, int ay, int bx, int by, int type)
{
{
        HWND    hwnd;
        HWND    hwnd;
        int     rx, ry;
        int     rx, ry;
        RECT    rc, rc2;
        RECT    rc, rc2;
 
 
        hwnd = MwPrepareDC(hdc);
        hwnd = MwPrepareDC(hdc);
        if(!hwnd)
        if(!hwnd)
                return;
                return;
 
 
        SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect);
        SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect);
        SetRect(&rc2, ax, ay, bx, by);
        SetRect(&rc2, ax, ay, bx, by);
        if(MwIsClientDC(hdc)) {
        if(MwIsClientDC(hdc)) {
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc2, 2);
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc2, 2);
        }
        }
 
 
        rx = (rc.right - rc.left)/2 - 1;
        rx = (rc.right - rc.left)/2 - 1;
        ry = (rc.bottom - rc.top)/2 - 1;
        ry = (rc.bottom - rc.top)/2 - 1;
        rc.left += rx;
        rc.left += rx;
        rc.top += ry;
        rc.top += ry;
 
 
        /* fill ellipse in current brush color*/
        /* fill ellipse in current brush color*/
        if(hdc->brush->style != BS_NULL && type == MWPIE) {
        if(hdc->brush->style != BS_NULL && type == MWPIE) {
                GdSetForeground(GdFindColor(hdc->brush->color));
                GdSetForeground(GdFindColor(hdc->brush->color));
                GdArc(hdc->psd, rc.left, rc.top, rx, ry,
                GdArc(hdc->psd, rc.left, rc.top, rx, ry,
                        rc2.left, rc2.top, rc2.right, rc2.bottom, MWPIE);
                        rc2.left, rc2.top, rc2.right, rc2.bottom, MWPIE);
        }
        }
 
 
        /* draw ellipse outline in current pen color*/
        /* draw ellipse outline in current pen color*/
        if(hdc->pen->style != PS_NULL) {
        if(hdc->pen->style != PS_NULL) {
                GdSetForeground(GdFindColor(hdc->pen->color));
                GdSetForeground(GdFindColor(hdc->pen->color));
                if(type == MWPIE)
                if(type == MWPIE)
                        type = MWARC;   /* MWARCOUTLINE?*/
                        type = MWARC;   /* MWARCOUTLINE?*/
                GdArc(hdc->psd, rc.left, rc.top, rx, ry,
                GdArc(hdc->psd, rc.left, rc.top, rx, ry,
                        rc2.left, rc2.top, rc2.right, rc2.bottom, type);
                        rc2.left, rc2.top, rc2.right, rc2.bottom, type);
        }
        }
}
}
 
 
BOOL WINAPI
BOOL WINAPI
Arc(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
Arc(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
        int nXStartArc, int nYStartArc, int nXEndArc, int nYEndArc)
        int nXStartArc, int nYStartArc, int nXEndArc, int nYEndArc)
{
{
        dopiearc(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect,
        dopiearc(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect,
                nXStartArc, nYStartArc, nXEndArc, nYEndArc, MWARC);
                nXStartArc, nYStartArc, nXEndArc, nYEndArc, MWARC);
        return TRUE;
        return TRUE;
}
}
 
 
BOOL WINAPI
BOOL WINAPI
Pie(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
Pie(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
        int nXRadial1, int nYRadial1, int nXRadial2, int nYRadial2)
        int nXRadial1, int nYRadial1, int nXRadial2, int nYRadial2)
{
{
        dopiearc(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect,
        dopiearc(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect,
                nXRadial1, nYRadial1, nXRadial2, nYRadial2, MWPIE);
                nXRadial1, nYRadial1, nXRadial2, nYRadial2, MWPIE);
        return TRUE;
        return TRUE;
}
}
 
 
BOOL WINAPI
BOOL WINAPI
Polygon(HDC hdc, CONST POINT *lpPoints, int nCount)
Polygon(HDC hdc, CONST POINT *lpPoints, int nCount)
{
{
        HWND    hwnd;
        HWND    hwnd;
        int     i;
        int     i;
        LPPOINT pp, ppAlloc = NULL;
        LPPOINT pp, ppAlloc = NULL;
 
 
        hwnd = MwPrepareDC(hdc);
        hwnd = MwPrepareDC(hdc);
        if(!hwnd)
        if(!hwnd)
                return FALSE;
                return FALSE;
 
 
        if(MwIsClientDC(hdc)) {
        if(MwIsClientDC(hdc)) {
                /* convert points to client coords*/
                /* convert points to client coords*/
                ppAlloc = (LPPOINT)malloc(nCount * sizeof(POINT));
                ppAlloc = (LPPOINT)malloc(nCount * sizeof(POINT));
                if(!ppAlloc)
                if(!ppAlloc)
                        return FALSE;
                        return FALSE;
                memcpy(ppAlloc, lpPoints, nCount*sizeof(POINT));
                memcpy(ppAlloc, lpPoints, nCount*sizeof(POINT));
                pp = ppAlloc;
                pp = ppAlloc;
                for(i=0; i<nCount; ++i)
                for(i=0; i<nCount; ++i)
                        ClientToScreen(hwnd, pp++);
                        ClientToScreen(hwnd, pp++);
                pp = ppAlloc;
                pp = ppAlloc;
        } else pp = (LPPOINT)lpPoints;
        } else pp = (LPPOINT)lpPoints;
 
 
        /* fill polygon in current brush color*/
        /* fill polygon in current brush color*/
        if(hdc->brush->style != BS_NULL) {
        if(hdc->brush->style != BS_NULL) {
                GdSetForeground(GdFindColor(hdc->brush->color));
                GdSetForeground(GdFindColor(hdc->brush->color));
                GdFillPoly(hdc->psd, nCount, pp);
                GdFillPoly(hdc->psd, nCount, pp);
        }
        }
 
 
        /* draw polygon outline in current pen color*/
        /* draw polygon outline in current pen color*/
        if(hdc->pen->style != PS_NULL) {
        if(hdc->pen->style != PS_NULL) {
                GdSetForeground(GdFindColor(hdc->pen->color));
                GdSetForeground(GdFindColor(hdc->pen->color));
                GdPoly(hdc->psd, nCount, pp);
                GdPoly(hdc->psd, nCount, pp);
        }
        }
 
 
        if(ppAlloc)
        if(ppAlloc)
                free(ppAlloc);
                free(ppAlloc);
        return TRUE;
        return TRUE;
}
}
 
 
/* draw nCount polygons*/
/* draw nCount polygons*/
BOOL WINAPI
BOOL WINAPI
PolyPolygon(HDC hdc, CONST POINT *lpPoints, LPINT lpPolyCounts, int nCount)
PolyPolygon(HDC hdc, CONST POINT *lpPoints, LPINT lpPolyCounts, int nCount)
{
{
        while(--nCount >= 0) {
        while(--nCount >= 0) {
                if (!Polygon(hdc, lpPoints, *lpPolyCounts))
                if (!Polygon(hdc, lpPoints, *lpPolyCounts))
                        return FALSE;
                        return FALSE;
                lpPoints += *lpPolyCounts++;
                lpPoints += *lpPolyCounts++;
        }
        }
        return TRUE;
        return TRUE;
}
}
 
 
int WINAPI
int WINAPI
FillRect(HDC hdc, CONST RECT *lprc, HBRUSH hbr)
FillRect(HDC hdc, CONST RECT *lprc, HBRUSH hbr)
{
{
        HWND            hwnd;
        HWND            hwnd;
        RECT            rc;
        RECT            rc;
        MWBRUSHOBJ *    obr = (MWBRUSHOBJ *)hbr;
        MWBRUSHOBJ *    obr = (MWBRUSHOBJ *)hbr;
        COLORREF        crFill;
        COLORREF        crFill;
 
 
        hwnd = MwPrepareDC(hdc);
        hwnd = MwPrepareDC(hdc);
        if(!hwnd || !obr)
        if(!hwnd || !obr)
                return FALSE;
                return FALSE;
 
 
        if(!lprc) {
        if(!lprc) {
                if(MwIsClientDC(hdc))
                if(MwIsClientDC(hdc))
                        GetClientRect(hwnd, &rc);
                        GetClientRect(hwnd, &rc);
                else
                else
                        GetWindowRect(hwnd, &rc);
                        GetWindowRect(hwnd, &rc);
                lprc = &rc;
                lprc = &rc;
        } else
        } else
                rc = *lprc;
                rc = *lprc;
        if(MwIsClientDC(hdc))
        if(MwIsClientDC(hdc))
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
 
 
        /* handle COLOR_xxx + 1 passed as HBRUSH*/
        /* handle COLOR_xxx + 1 passed as HBRUSH*/
        if((PTRTOINT)obr <= MAXSYSCOLORS)
        if((PTRTOINT)obr <= MAXSYSCOLORS)
                crFill = GetSysColor((int)obr-1);
                crFill = GetSysColor((int)obr-1);
        else {
        else {
                /* get color from passed HBRUSH*/
                /* get color from passed HBRUSH*/
                if(obr->style == BS_NULL)
                if(obr->style == BS_NULL)
                        return TRUE;
                        return TRUE;
                crFill = obr->color;
                crFill = obr->color;
        }
        }
 
 
        /* fill rectangle in passed brush color*/
        /* fill rectangle in passed brush color*/
        GdSetForeground(GdFindColor(crFill));
        GdSetForeground(GdFindColor(crFill));
        GdFillRect(hdc->psd, rc.left, rc.top,
        GdFillRect(hdc->psd, rc.left, rc.top,
                rc.right - rc.left, rc.bottom - rc.top);
                rc.right - rc.left, rc.bottom - rc.top);
        return TRUE;
        return TRUE;
}
}
 
 
/* ascii*/
/* ascii*/
BOOL WINAPI
BOOL WINAPI
TextOut(HDC hdc, int x, int y, LPCSTR lpszString, int cbString)
TextOut(HDC hdc, int x, int y, LPCSTR lpszString, int cbString)
{
{
        /* kaffe port wants MWTF_UTF8 here...*/
        /* kaffe port wants MWTF_UTF8 here...*/
        return MwExtTextOut(hdc, x, y, 0, NULL, lpszString, cbString, NULL,
        return MwExtTextOut(hdc, x, y, 0, NULL, lpszString, cbString, NULL,
                MWTF_ASCII);
                MWTF_ASCII);
}
}
 
 
/* ascii*/
/* ascii*/
BOOL WINAPI
BOOL WINAPI
ExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
ExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
        LPCSTR lpszString, UINT cbCount, CONST INT *lpDx)
        LPCSTR lpszString, UINT cbCount, CONST INT *lpDx)
{
{
        return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString,
        return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString,
                cbCount, lpDx, MWTF_ASCII);
                cbCount, lpDx, MWTF_ASCII);
}
}
 
 
/* unicode*/
/* unicode*/
BOOL WINAPI
BOOL WINAPI
ExtTextOutW(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
ExtTextOutW(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
        LPCWSTR lpszString, UINT cbCount, CONST INT *lpDx)
        LPCWSTR lpszString, UINT cbCount, CONST INT *lpDx)
{
{
        return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString,
        return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString,
                cbCount, lpDx, MWTF_UC16);
                cbCount, lpDx, MWTF_UC16);
}
}
 
 
/* internal version of ExtTextOut, passed flags for text data type*/
/* internal version of ExtTextOut, passed flags for text data type*/
static BOOL
static BOOL
MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
        LPCVOID lpszString, UINT cbCount, CONST INT *lpDx, int flags)
        LPCVOID lpszString, UINT cbCount, CONST INT *lpDx, int flags)
{
{
        HWND    hwnd;
        HWND    hwnd;
        POINT   pt;
        POINT   pt;
        RECT    rc;
        RECT    rc;
 
 
        hwnd = MwPrepareDC(hdc);
        hwnd = MwPrepareDC(hdc);
        if(!hwnd)
        if(!hwnd)
                return FALSE;
                return FALSE;
 
 
        pt.x = x;
        pt.x = x;
        pt.y = y;
        pt.y = y;
        if(MwIsClientDC(hdc))
        if(MwIsClientDC(hdc))
                ClientToScreen(hwnd, &pt);
                ClientToScreen(hwnd, &pt);
 
 
        /* optionally fill passed rectangle*/
        /* optionally fill passed rectangle*/
        if(lprc && (fuOptions&ETO_OPAQUE)) {
        if(lprc && (fuOptions&ETO_OPAQUE)) {
                rc = *lprc;
                rc = *lprc;
                if(MwIsClientDC(hdc))
                if(MwIsClientDC(hdc))
                        MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
                        MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
 
 
                /* fill rectangle with current background color*/
                /* fill rectangle with current background color*/
                GdSetForeground(GdFindColor(hdc->bkcolor));
                GdSetForeground(GdFindColor(hdc->bkcolor));
                GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left,
                GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left,
                        rc.bottom - rc.top);
                        rc.bottom - rc.top);
                GdSetUseBackground(FALSE);
                GdSetUseBackground(FALSE);
        } else {
        } else {
                /* use current background mode for text background draw*/
                /* use current background mode for text background draw*/
                GdSetUseBackground(hdc->bkmode == OPAQUE? TRUE: FALSE);
                GdSetUseBackground(hdc->bkmode == OPAQUE? TRUE: FALSE);
                /* always set background color in case GdArea is
                /* always set background color in case GdArea is
                 * used to draw, which compares gr_foreground != gr_background
                 * used to draw, which compares gr_foreground != gr_background
                 * if gr_usebg is false...
                 * if gr_usebg is false...
                 */
                 */
                /*if(hdc->bkmode == OPAQUE)*/
                /*if(hdc->bkmode == OPAQUE)*/
                        GdSetBackground(GdFindColor(hdc->bkcolor));
                        GdSetBackground(GdFindColor(hdc->bkcolor));
        }
        }
 
 
        /* nyi: lpDx*/
        /* nyi: lpDx*/
 
 
        /* draw text in current text foreground and background color*/
        /* draw text in current text foreground and background color*/
        GdSetForeground(GdFindColor(hdc->textcolor));
        GdSetForeground(GdFindColor(hdc->textcolor));
        GdSetFont(hdc->font->pfont);
        GdSetFont(hdc->font->pfont);
 
 
        /* this whole text alignment thing needs rewriting*/
        /* this whole text alignment thing needs rewriting*/
        if((hdc->textalign & TA_BASELINE) == TA_BASELINE) {
        if((hdc->textalign & TA_BASELINE) == TA_BASELINE) {
                 /* this is not right... changed for kaffe port
                 /* this is not right... changed for kaffe port
                flags |= MWTF_TOP;
                flags |= MWTF_TOP;
                 */
                 */
                flags |= MWTF_BASELINE;
                flags |= MWTF_BASELINE;
        } else if(hdc->textalign & TA_BOTTOM) {
        } else if(hdc->textalign & TA_BOTTOM) {
                MWCOORD ph, pw, pb;
                MWCOORD ph, pw, pb;
 
 
                if(lprc)
                if(lprc)
                        pt.y += lprc->bottom - lprc->top;
                        pt.y += lprc->bottom - lprc->top;
                else {
                else {
                        GdGetTextSize(hdc->font->pfont, lpszString, cbCount,
                        GdGetTextSize(hdc->font->pfont, lpszString, cbCount,
                                &pw, &ph, &pb, flags);
                                &pw, &ph, &pb, flags);
                        pt.y += ph;
                        pt.y += ph;
                }
                }
                flags |= MWTF_BOTTOM;
                flags |= MWTF_BOTTOM;
        } else
        } else
                flags |= MWTF_TOP;
                flags |= MWTF_TOP;
        GdText(hdc->psd, pt.x, pt.y, lpszString, cbCount, flags);
        GdText(hdc->psd, pt.x, pt.y, lpszString, cbCount, flags);
 
 
        return TRUE;
        return TRUE;
}
}
 
 
/* ascii*/
/* ascii*/
int WINAPI
int WINAPI
DrawTextA(HDC hdc, LPCSTR lpString, int nCount, LPRECT lpRect, UINT uFormat)
DrawTextA(HDC hdc, LPCSTR lpString, int nCount, LPRECT lpRect, UINT uFormat)
{
{
        return MwDrawText(hdc, lpString, nCount, lpRect, uFormat, MWTF_ASCII);
        return MwDrawText(hdc, lpString, nCount, lpRect, uFormat, MWTF_ASCII);
}
}
 
 
/* unicode*/
/* unicode*/
int WINAPI
int WINAPI
DrawTextW(HDC hdc, LPCWSTR lpString, int nCount, LPRECT lpRect, UINT uFormat)
DrawTextW(HDC hdc, LPCWSTR lpString, int nCount, LPRECT lpRect, UINT uFormat)
{
{
        return MwDrawText(hdc, lpString, nCount, lpRect, uFormat, MWTF_UC16);
        return MwDrawText(hdc, lpString, nCount, lpRect, uFormat, MWTF_UC16);
}
}
 
 
/* note: many DT_x aren't implemented in this function*/
/* note: many DT_x aren't implemented in this function*/
/* internal version of DrawText, passed flags for text data type*/
/* internal version of DrawText, passed flags for text data type*/
static int
static int
MwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect, UINT uFormat,
MwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect, UINT uFormat,
        int flags)
        int flags)
{
{
        MWCOORD x, y, width, height, baseline;
        MWCOORD x, y, width, height, baseline;
 
 
        if(nCount == -1)
        if(nCount == -1)
                nCount = strlen(lpString);
                nCount = strlen(lpString);
 
 
        if(uFormat & (DT_CALCRECT|DT_CENTER|DT_RIGHT)) {
        if(uFormat & (DT_CALCRECT|DT_CENTER|DT_RIGHT)) {
                if(!hdc)
                if(!hdc)
                        return 0;
                        return 0;
                GdGetTextSize(hdc->font->pfont, lpString, nCount,
                GdGetTextSize(hdc->font->pfont, lpString, nCount,
                        &width, &height, &baseline, MWTF_ASCII);
                        &width, &height, &baseline, MWTF_ASCII);
        }
        }
        x = lpRect->left;
        x = lpRect->left;
        y = lpRect->top;
        y = lpRect->top;
 
 
        if(uFormat & DT_CALCRECT) {
        if(uFormat & DT_CALCRECT) {
                lpRect->right = x + width;
                lpRect->right = x + width;
                lpRect->bottom = y + height;
                lpRect->bottom = y + height;
                return height;
                return height;
        }
        }
 
 
        if(uFormat & DT_CENTER)
        if(uFormat & DT_CENTER)
                x = (lpRect->left + lpRect->right - width) / 2;
                x = (lpRect->left + lpRect->right - width) / 2;
        else if(uFormat & DT_RIGHT)
        else if(uFormat & DT_RIGHT)
                x += lpRect->right - width;
                x += lpRect->right - width;
 
 
        /* draw text at DT_TOP using current fg, bg and bkmode*/
        /* draw text at DT_TOP using current fg, bg and bkmode*/
        MwExtTextOut(hdc, x, y, 0, NULL, lpString, nCount, NULL, flags);
        MwExtTextOut(hdc, x, y, 0, NULL, lpString, nCount, NULL, flags);
        return height;
        return height;
}
}
 
 
/* Microwindows only*/
/* Microwindows only*/
BOOL WINAPI
BOOL WINAPI
DrawDIB(HDC hdc,int x,int y,PMWIMAGEHDR pimage)
DrawDIB(HDC hdc,int x,int y,PMWIMAGEHDR pimage)
{
{
        HWND            hwnd;
        HWND            hwnd;
        POINT           pt;
        POINT           pt;
 
 
        hwnd = MwPrepareDC(hdc);
        hwnd = MwPrepareDC(hdc);
        if(!hwnd || !pimage)
        if(!hwnd || !pimage)
                return FALSE;
                return FALSE;
        pt.x = x;
        pt.x = x;
        pt.y = y;
        pt.y = y;
        if(MwIsClientDC(hdc))
        if(MwIsClientDC(hdc))
                ClientToScreen(hwnd, &pt);
                ClientToScreen(hwnd, &pt);
 
 
        GdDrawImage(hdc->psd, pt.x, pt.y, pimage);
        GdDrawImage(hdc->psd, pt.x, pt.y, pimage);
        return TRUE;
        return TRUE;
}
}
 
 
/* define color scheme: A (tan), B (winstd) or C (old)*/
/* define color scheme: A (tan), B (winstd) or C (old)*/
#if ELKS
#if ELKS
#define B
#define B
#else
#else
#define A
#define A
#endif
#endif
 
 
#define A_RGB(r,g,b)
#define A_RGB(r,g,b)
#define B_RGB(r,g,b)
#define B_RGB(r,g,b)
#define C_RGB(r,g,b)
#define C_RGB(r,g,b)
 
 
#ifdef A
#ifdef A
#undef  A_RGB
#undef  A_RGB
#define A_RGB(r,g,b)    RGB(r,g,b),
#define A_RGB(r,g,b)    RGB(r,g,b),
#endif
#endif
#ifdef B
#ifdef B
#undef  B_RGB
#undef  B_RGB
#define B_RGB(r,g,b)    RGB(r,g,b),
#define B_RGB(r,g,b)    RGB(r,g,b),
#endif
#endif
#ifdef C
#ifdef C
#undef  C_RGB
#undef  C_RGB
#define C_RGB(r,g,b)    RGB(r,g,b),
#define C_RGB(r,g,b)    RGB(r,g,b),
#endif
#endif
 
 
static COLORREF sysColors[MAXSYSCOLORS] = {
static COLORREF sysColors[MAXSYSCOLORS] = {
        RGB(192, 192, 192),     /* COLOR_SCROLLBAR          0*/
        RGB(192, 192, 192),     /* COLOR_SCROLLBAR          0*/
        RGB(  0, 128, 128),     /* COLOR_BACKGROUND          */
        RGB(  0, 128, 128),     /* COLOR_BACKGROUND          */
        A_RGB(128,   0,   0)      /* COLOR_ACTIVECAPTION       */
        A_RGB(128,   0,   0)      /* COLOR_ACTIVECAPTION       */
        B_RGB(128,   0, 128)     /* COLOR_ACTIVECAPTION       */
        B_RGB(128,   0, 128)     /* COLOR_ACTIVECAPTION       */
        C_RGB(128,   0, 128)     /* COLOR_ACTIVECAPTION       */
        C_RGB(128,   0, 128)     /* COLOR_ACTIVECAPTION       */
        A_RGB(162, 141, 104)    /* COLOR_INACTIVECAPTION     */
        A_RGB(162, 141, 104)    /* COLOR_INACTIVECAPTION     */
        B_RGB(128, 128, 128)    /* COLOR_INACTIVECAPTION     */
        B_RGB(128, 128, 128)    /* COLOR_INACTIVECAPTION     */
        C_RGB(  0,  64, 128)     /* COLOR_INACTIVECAPTION     */
        C_RGB(  0,  64, 128)     /* COLOR_INACTIVECAPTION     */
        RGB(192, 192, 192),     /* COLOR_MENU                */
        RGB(192, 192, 192),     /* COLOR_MENU                */
        RGB(255, 255, 255),     /* COLOR_WINDOW             5*/
        RGB(255, 255, 255),     /* COLOR_WINDOW             5*/
        RGB(  0,   0,   0),     /* COLOR_WINDOWFRAME         */
        RGB(  0,   0,   0),     /* COLOR_WINDOWFRAME         */
        RGB(  0,   0,   0),     /* COLOR_MENUTEXT            */
        RGB(  0,   0,   0),     /* COLOR_MENUTEXT            */
        RGB(  0,   0,   0),     /* COLOR_WINDOWTEXT          */
        RGB(  0,   0,   0),     /* COLOR_WINDOWTEXT          */
        RGB(255, 255, 255),     /* COLOR_CAPTIONTEXT         */
        RGB(255, 255, 255),     /* COLOR_CAPTIONTEXT         */
        RGB(192, 192, 192),     /* COLOR_ACTIVEBORDER      10*/
        RGB(192, 192, 192),     /* COLOR_ACTIVEBORDER      10*/
        RGB(192, 192, 192),     /* COLOR_INACTIVEBORDER      */
        RGB(192, 192, 192),     /* COLOR_INACTIVEBORDER      */
        RGB(128, 128, 128),     /* COLOR_APPWORKSPACE        */
        RGB(128, 128, 128),     /* COLOR_APPWORKSPACE        */
        RGB(128,   0,   0),     /* COLOR_HIGHLIGHT           */
        RGB(128,   0,   0),     /* COLOR_HIGHLIGHT           */
        RGB(255, 255, 255),     /* COLOR_HIGHLIGHTTEXT       */
        RGB(255, 255, 255),     /* COLOR_HIGHLIGHTTEXT       */
        A_RGB(213, 204, 187)    /* COLOR_BTNFACE           15*/
        A_RGB(213, 204, 187)    /* COLOR_BTNFACE           15*/
        B_RGB(192, 192, 192)    /* COLOR_BTNFACE           15*/
        B_RGB(192, 192, 192)    /* COLOR_BTNFACE           15*/
        C_RGB(160, 160, 160)    /* COLOR_BTNFACE           15*/
        C_RGB(160, 160, 160)    /* COLOR_BTNFACE           15*/
        A_RGB(162, 141, 104)    /* COLOR_BTNSHADOW           */
        A_RGB(162, 141, 104)    /* COLOR_BTNSHADOW           */
        B_RGB(128, 128, 128)    /* COLOR_BTNSHADOW           */
        B_RGB(128, 128, 128)    /* COLOR_BTNSHADOW           */
        C_RGB(128, 128, 128)    /* COLOR_BTNSHADOW           */
        C_RGB(128, 128, 128)    /* COLOR_BTNSHADOW           */
        RGB( 64,  64,  64),     /* COLOR_GRAYTEXT            */
        RGB( 64,  64,  64),     /* COLOR_GRAYTEXT            */
        RGB(  0,   0,   0),     /* COLOR_BTNTEXT             */
        RGB(  0,   0,   0),     /* COLOR_BTNTEXT             */
        RGB(192, 192, 192),     /* COLOR_INACTIVECAPTIONTEXT */
        RGB(192, 192, 192),     /* COLOR_INACTIVECAPTIONTEXT */
        A_RGB(234, 230, 221)    /* COLOR_BTNHIGHLIGHT      20*/
        A_RGB(234, 230, 221)    /* COLOR_BTNHIGHLIGHT      20*/
        B_RGB(255, 255, 255)    /* COLOR_BTNHIGHLIGHT      20*/
        B_RGB(255, 255, 255)    /* COLOR_BTNHIGHLIGHT      20*/
        C_RGB(223, 223, 223)    /* COLOR_BTNHIGHLIGHT      20*/
        C_RGB(223, 223, 223)    /* COLOR_BTNHIGHLIGHT      20*/
        RGB(  0,   0,   0),     /* COLOR_3DDKSHADOW          */
        RGB(  0,   0,   0),     /* COLOR_3DDKSHADOW          */
        A_RGB(213, 204, 187)    /* COLOR_3DLIGHT             */
        A_RGB(213, 204, 187)    /* COLOR_3DLIGHT             */
        B_RGB(223, 223, 223)    /* COLOR_3DLIGHT             */
        B_RGB(223, 223, 223)    /* COLOR_3DLIGHT             */
        C_RGB(192, 192, 192)    /* COLOR_3DLIGHT             */
        C_RGB(192, 192, 192)    /* COLOR_3DLIGHT             */
        RGB(  0,   0,   0),     /* COLOR_INFOTEXT            */
        RGB(  0,   0,   0),     /* COLOR_INFOTEXT            */
        RGB(225, 255, 255),     /* COLOR_INFOBK              */
        RGB(225, 255, 255),     /* COLOR_INFOBK              */
        RGB(184, 180, 184),     /* COLOR_ALTERNATEBTNFACE  25*/
        RGB(184, 180, 184),     /* COLOR_ALTERNATEBTNFACE  25*/
        RGB(  0,   0, 255),     /* COLOR_HOTLIGHT              */
        RGB(  0,   0, 255),     /* COLOR_HOTLIGHT              */
        RGB( 16, 132, 208),     /* COLOR_GRADIENTACTIVECAPTION */
        RGB( 16, 132, 208),     /* COLOR_GRADIENTACTIVECAPTION */
        RGB(184, 180, 184)      /* COLOR_GRADIENTINACTIVECAPTION 28*/
        RGB(184, 180, 184)      /* COLOR_GRADIENTINACTIVECAPTION 28*/
};
};
 
 
DWORD WINAPI
DWORD WINAPI
GetSysColor(int nIndex)
GetSysColor(int nIndex)
{
{
        if(nIndex >= 0 && nIndex < MAXSYSCOLORS)
        if(nIndex >= 0 && nIndex < MAXSYSCOLORS)
                return sysColors[nIndex];
                return sysColors[nIndex];
        return 0;
        return 0;
}
}
 
 
COLORREF WINAPI
COLORREF WINAPI
SetSysColor(int nIndex, COLORREF crColor)       /* Microwindows only*/
SetSysColor(int nIndex, COLORREF crColor)       /* Microwindows only*/
{
{
        COLORREF oldColor;
        COLORREF oldColor;
 
 
        if(nIndex >= 0 && nIndex < MAXSYSCOLORS) {
        if(nIndex >= 0 && nIndex < MAXSYSCOLORS) {
                oldColor = sysColors[nIndex];
                oldColor = sysColors[nIndex];
                sysColors[nIndex] = crColor;
                sysColors[nIndex] = crColor;
                return oldColor;
                return oldColor;
        }
        }
        return 0;
        return 0;
}
}
 
 
static MWBRUSHOBJ OBJ_WHITE_BRUSH = {
static MWBRUSHOBJ OBJ_WHITE_BRUSH = {
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(255, 255, 255)
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(255, 255, 255)
};
};
 
 
static MWBRUSHOBJ OBJ_LTGRAY_BRUSH = {
static MWBRUSHOBJ OBJ_LTGRAY_BRUSH = {
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(192, 192, 192)
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(192, 192, 192)
};
};
 
 
static MWBRUSHOBJ OBJ_GRAY_BRUSH = {
static MWBRUSHOBJ OBJ_GRAY_BRUSH = {
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(128, 128, 128)
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(128, 128, 128)
};
};
 
 
static MWBRUSHOBJ OBJ_DKGRAY_BRUSH = {
static MWBRUSHOBJ OBJ_DKGRAY_BRUSH = {
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(32, 32, 32)
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(32, 32, 32)
};
};
 
 
static MWBRUSHOBJ OBJ_BLACK_BRUSH = {
static MWBRUSHOBJ OBJ_BLACK_BRUSH = {
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(0, 0, 0)
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(0, 0, 0)
};
};
 
 
static MWBRUSHOBJ OBJ_NULL_BRUSH = {
static MWBRUSHOBJ OBJ_NULL_BRUSH = {
        {OBJ_BRUSH, TRUE}, BS_NULL, RGB(0, 0, 0)
        {OBJ_BRUSH, TRUE}, BS_NULL, RGB(0, 0, 0)
};
};
 
 
static MWPENOBJ OBJ_WHITE_PEN = {
static MWPENOBJ OBJ_WHITE_PEN = {
        {OBJ_PEN, TRUE}, PS_SOLID, RGB(255, 255, 255)
        {OBJ_PEN, TRUE}, PS_SOLID, RGB(255, 255, 255)
};
};
 
 
static MWPENOBJ OBJ_BLACK_PEN = {
static MWPENOBJ OBJ_BLACK_PEN = {
        {OBJ_PEN, TRUE}, PS_SOLID, RGB(0, 0, 0)
        {OBJ_PEN, TRUE}, PS_SOLID, RGB(0, 0, 0)
};
};
 
 
static MWPENOBJ OBJ_NULL_PEN = {
static MWPENOBJ OBJ_NULL_PEN = {
        {OBJ_PEN, TRUE}, PS_NULL, RGB(0, 0, 0)
        {OBJ_PEN, TRUE}, PS_NULL, RGB(0, 0, 0)
};
};
 
 
static MWFONTOBJ OBJ_OEM_FIXED_FONT = {
static MWFONTOBJ OBJ_OEM_FIXED_FONT = {
        {OBJ_FONT, TRUE}, NULL, MWFONT_OEM_FIXED
        {OBJ_FONT, TRUE}, NULL, MWFONT_OEM_FIXED
};
};
 
 
static MWFONTOBJ OBJ_ANSI_FIXED_FONT = {
static MWFONTOBJ OBJ_ANSI_FIXED_FONT = {
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_FIXED
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_FIXED
};
};
 
 
static MWFONTOBJ OBJ_ANSI_VAR_FONT = {
static MWFONTOBJ OBJ_ANSI_VAR_FONT = {
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_VAR
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_VAR
};
};
 
 
static MWFONTOBJ OBJ_SYSTEM_FONT = {
static MWFONTOBJ OBJ_SYSTEM_FONT = {
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_VAR
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_VAR
};
};
 
 
static MWFONTOBJ OBJ_DEVICE_DEFAULT_FONT = {
static MWFONTOBJ OBJ_DEVICE_DEFAULT_FONT = {
        {OBJ_FONT, TRUE}, NULL, MWFONT_OEM_FIXED
        {OBJ_FONT, TRUE}, NULL, MWFONT_OEM_FIXED
};
};
 
 
static MWFONTOBJ OBJ_SYSTEM_FIXED_FONT = {
static MWFONTOBJ OBJ_SYSTEM_FIXED_FONT = {
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_FIXED
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_FIXED
};
};
 
 
static MWFONTOBJ OBJ_DEFAULT_GUI_FONT = {
static MWFONTOBJ OBJ_DEFAULT_GUI_FONT = {
        {OBJ_FONT, TRUE}, NULL, MWFONT_GUI_VAR
        {OBJ_FONT, TRUE}, NULL, MWFONT_GUI_VAR
};
};
 
 
static struct hgdiobj *stockObjects[MAXSTOCKOBJECTS] = {
static struct hgdiobj *stockObjects[MAXSTOCKOBJECTS] = {
        (struct hgdiobj *)&OBJ_WHITE_BRUSH,             /* WHITE_BRUSH*/
        (struct hgdiobj *)&OBJ_WHITE_BRUSH,             /* WHITE_BRUSH*/
        (struct hgdiobj *)&OBJ_LTGRAY_BRUSH,            /* LTGRAY_BRUSH*/
        (struct hgdiobj *)&OBJ_LTGRAY_BRUSH,            /* LTGRAY_BRUSH*/
        (struct hgdiobj *)&OBJ_GRAY_BRUSH,              /* GRAY_BRUSH*/
        (struct hgdiobj *)&OBJ_GRAY_BRUSH,              /* GRAY_BRUSH*/
        (struct hgdiobj *)&OBJ_DKGRAY_BRUSH,            /* DKGRAY_BRUSH*/
        (struct hgdiobj *)&OBJ_DKGRAY_BRUSH,            /* DKGRAY_BRUSH*/
        (struct hgdiobj *)&OBJ_BLACK_BRUSH,             /* BLACK_BRUSH*/
        (struct hgdiobj *)&OBJ_BLACK_BRUSH,             /* BLACK_BRUSH*/
        (struct hgdiobj *)&OBJ_NULL_BRUSH,              /* NULL_BRUSH*/
        (struct hgdiobj *)&OBJ_NULL_BRUSH,              /* NULL_BRUSH*/
        (struct hgdiobj *)&OBJ_WHITE_PEN,               /* WHITE_PEN*/
        (struct hgdiobj *)&OBJ_WHITE_PEN,               /* WHITE_PEN*/
        (struct hgdiobj *)&OBJ_BLACK_PEN,               /* BLACK_PEN*/
        (struct hgdiobj *)&OBJ_BLACK_PEN,               /* BLACK_PEN*/
        (struct hgdiobj *)&OBJ_NULL_PEN,                /* NULL_PEN*/
        (struct hgdiobj *)&OBJ_NULL_PEN,                /* NULL_PEN*/
        (struct hgdiobj *)NULL,
        (struct hgdiobj *)NULL,
        (struct hgdiobj *)&OBJ_OEM_FIXED_FONT,          /* OEM_FIXED_FONT*/
        (struct hgdiobj *)&OBJ_OEM_FIXED_FONT,          /* OEM_FIXED_FONT*/
        (struct hgdiobj *)&OBJ_ANSI_FIXED_FONT,         /* ANSI_FIXED_FONT*/
        (struct hgdiobj *)&OBJ_ANSI_FIXED_FONT,         /* ANSI_FIXED_FONT*/
        (struct hgdiobj *)&OBJ_ANSI_VAR_FONT,           /* ANSI_VAR_FONT*/
        (struct hgdiobj *)&OBJ_ANSI_VAR_FONT,           /* ANSI_VAR_FONT*/
        (struct hgdiobj *)&OBJ_SYSTEM_FONT,             /* SYSTEM_FONT*/
        (struct hgdiobj *)&OBJ_SYSTEM_FONT,             /* SYSTEM_FONT*/
        (struct hgdiobj *)&OBJ_DEVICE_DEFAULT_FONT,     /* DEVICE_DEFAULT_FONT*/
        (struct hgdiobj *)&OBJ_DEVICE_DEFAULT_FONT,     /* DEVICE_DEFAULT_FONT*/
        (struct hgdiobj *)NULL,                         /* DEFAULT_PALETTE*/
        (struct hgdiobj *)NULL,                         /* DEFAULT_PALETTE*/
        (struct hgdiobj *)&OBJ_SYSTEM_FIXED_FONT,       /* SYSTEM_FIXED_FONT*/
        (struct hgdiobj *)&OBJ_SYSTEM_FIXED_FONT,       /* SYSTEM_FIXED_FONT*/
        (struct hgdiobj *)&OBJ_DEFAULT_GUI_FONT         /* DEFAULT_GUI_FONT*/
        (struct hgdiobj *)&OBJ_DEFAULT_GUI_FONT         /* DEFAULT_GUI_FONT*/
};
};
 
 
HGDIOBJ WINAPI
HGDIOBJ WINAPI
GetStockObject(int nObject)
GetStockObject(int nObject)
{
{
        HGDIOBJ         pObj;
        HGDIOBJ         pObj;
        MWFONTOBJ *     pFont;
        MWFONTOBJ *     pFont;
 
 
        if(nObject >= 0 && nObject < MAXSTOCKOBJECTS) {
        if(nObject >= 0 && nObject < MAXSTOCKOBJECTS) {
                pObj = stockObjects[nObject];
                pObj = stockObjects[nObject];
 
 
                /* create stock fonts on first access*/
                /* create stock fonts on first access*/
                if(pObj->hdr.type == OBJ_FONT) {
                if(pObj->hdr.type == OBJ_FONT) {
                        pFont = (MWFONTOBJ *)pObj;
                        pFont = (MWFONTOBJ *)pObj;
                        if(pFont->pfont == NULL) {
                        if(pFont->pfont == NULL) {
                                pFont->pfont = GdCreateFont(&scrdev,
                                pFont->pfont = GdCreateFont(&scrdev,
                                        pFont->name, 0, NULL);
                                        pFont->name, 0, NULL);
                        }
                        }
                        return pObj;
                        return pObj;
                }
                }
 
 
                /* implement multiple color schemes with
                /* implement multiple color schemes with
                 * standard background brushes...
                 * standard background brushes...
                 */
                 */
                switch(nObject) {
                switch(nObject) {
                case LTGRAY_BRUSH:
                case LTGRAY_BRUSH:
                case GRAY_BRUSH:
                case GRAY_BRUSH:
                        ((MWBRUSHOBJ *)pObj)->color =GetSysColor(COLOR_BTNFACE);
                        ((MWBRUSHOBJ *)pObj)->color =GetSysColor(COLOR_BTNFACE);
                        break;
                        break;
                case DKGRAY_BRUSH:
                case DKGRAY_BRUSH:
                        ((MWBRUSHOBJ *)pObj)->color =
                        ((MWBRUSHOBJ *)pObj)->color =
                                GetSysColor(COLOR_BTNSHADOW);
                                GetSysColor(COLOR_BTNSHADOW);
                        break;
                        break;
                }
                }
                return pObj;
                return pObj;
        }
        }
        return NULL;
        return NULL;
}
}
 
 
HGDIOBJ WINAPI
HGDIOBJ WINAPI
SelectObject(HDC hdc, HGDIOBJ hObject)
SelectObject(HDC hdc, HGDIOBJ hObject)
{
{
        HGDIOBJ         objOrg;
        HGDIOBJ         objOrg;
        MWBITMAPOBJ *   pb;
        MWBITMAPOBJ *   pb;
 
 
        if(!hdc || !hObject)
        if(!hdc || !hObject)
                return NULL;
                return NULL;
 
 
        switch(hObject->hdr.type) {
        switch(hObject->hdr.type) {
        case OBJ_PEN:
        case OBJ_PEN:
                objOrg = (HGDIOBJ)hdc->pen;
                objOrg = (HGDIOBJ)hdc->pen;
                hdc->pen = (MWPENOBJ *)hObject;
                hdc->pen = (MWPENOBJ *)hObject;
                break;
                break;
        case OBJ_BRUSH:
        case OBJ_BRUSH:
                objOrg = (HGDIOBJ)hdc->brush;
                objOrg = (HGDIOBJ)hdc->brush;
                hdc->brush = (MWBRUSHOBJ *)hObject;
                hdc->brush = (MWBRUSHOBJ *)hObject;
                break;
                break;
        case OBJ_FONT:
        case OBJ_FONT:
                objOrg = (HGDIOBJ)hdc->font;
                objOrg = (HGDIOBJ)hdc->font;
                hdc->font = (MWFONTOBJ *)hObject;
                hdc->font = (MWFONTOBJ *)hObject;
                break;
                break;
        case OBJ_BITMAP:
        case OBJ_BITMAP:
                /* must be memory dc to select bitmap*/
                /* must be memory dc to select bitmap*/
                if(!(hdc->psd->flags&PSF_MEMORY))
                if(!(hdc->psd->flags&PSF_MEMORY))
                        return NULL;
                        return NULL;
                objOrg = (HGDIOBJ)hdc->bitmap;
                objOrg = (HGDIOBJ)hdc->bitmap;
 
 
                /* setup mem dc for drawing into bitmap*/
                /* setup mem dc for drawing into bitmap*/
                pb = (MWBITMAPOBJ *)hObject;
                pb = (MWBITMAPOBJ *)hObject;
 
 
                /* init memory context*/
                /* init memory context*/
                if (!hdc->psd->MapMemGC(hdc->psd, pb->width, pb->height,
                if (!hdc->psd->MapMemGC(hdc->psd, pb->width, pb->height,
                        pb->planes, pb->bpp, pb->linelen, pb->size,
                        pb->planes, pb->bpp, pb->linelen, pb->size,
                        &pb->bits[0]))
                        &pb->bits[0]))
                                return NULL;
                                return NULL;
 
 
                hdc->bitmap = (MWBITMAPOBJ *)hObject;
                hdc->bitmap = (MWBITMAPOBJ *)hObject;
                break;
                break;
#if UPDATEREGIONS
#if UPDATEREGIONS
        case OBJ_REGION:
        case OBJ_REGION:
                /*objOrg = (HGDIOBJ)hdc->region;*/
                /*objOrg = (HGDIOBJ)hdc->region;*/
                objOrg = NULL;  /* FIXME? hdc->region is destroyed below*/
                objOrg = NULL;  /* FIXME? hdc->region is destroyed below*/
                SelectClipRgn(hdc, (HRGN)hObject);
                SelectClipRgn(hdc, (HRGN)hObject);
                break;
                break;
#endif
#endif
        default:
        default:
                return NULL;
                return NULL;
        }
        }
 
 
        return objOrg;
        return objOrg;
}
}
 
 
BOOL WINAPI
BOOL WINAPI
DeleteObject(HGDIOBJ hObject)
DeleteObject(HGDIOBJ hObject)
{
{
        if(!hObject || hObject->hdr.stockobj)
        if(!hObject || hObject->hdr.stockobj)
                return FALSE;
                return FALSE;
        if(hObject->hdr.type == OBJ_FONT)
        if(hObject->hdr.type == OBJ_FONT)
                GdDestroyFont(((MWFONTOBJ *)hObject)->pfont);
                GdDestroyFont(((MWFONTOBJ *)hObject)->pfont);
        if(hObject->hdr.type == OBJ_REGION)
        if(hObject->hdr.type == OBJ_REGION)
                GdDestroyRegion(((MWRGNOBJ *)hObject)->rgn);
                GdDestroyRegion(((MWRGNOBJ *)hObject)->rgn);
        GdItemFree(hObject);
        GdItemFree(hObject);
        return TRUE;
        return TRUE;
}
}
 
 
#if UPDATEREGIONS
#if UPDATEREGIONS
/* region is passed in client coords (win32 api doc bug)*/
/* region is passed in client coords (win32 api doc bug)*/
int WINAPI
int WINAPI
SelectClipRgn(HDC hdc, HRGN hrgn)
SelectClipRgn(HDC hdc, HRGN hrgn)
{
{
        return ExtSelectClipRgn(hdc, hrgn, RGN_COPY);
        return ExtSelectClipRgn(hdc, hrgn, RGN_COPY);
}
}
 
 
/*
/*
 * Select a user clip region into DC, recalculate final clipregion.
 * Select a user clip region into DC, recalculate final clipregion.
 * Only a copy of the passed region is used.
 * Only a copy of the passed region is used.
 */
 */
/* region is passed in client coords (win32 api doc bug)*/
/* region is passed in client coords (win32 api doc bug)*/
int WINAPI
int WINAPI
ExtSelectClipRgn(HDC hdc, HRGN hrgn, int fnMode)
ExtSelectClipRgn(HDC hdc, HRGN hrgn, int fnMode)
{
{
        HRGN    newrgn;
        HRGN    newrgn;
 
 
        if(!hdc)
        if(!hdc)
                return ERROR;
                return ERROR;
        if(hdc->region != (MWRGNOBJ *)hrgn) {
        if(hdc->region != (MWRGNOBJ *)hrgn) {
                /* combine region if not null*/
                /* combine region if not null*/
                if(hrgn) {
                if(hrgn) {
                        newrgn = CreateRectRgn(0, 0, 0, 0);
                        newrgn = CreateRectRgn(0, 0, 0, 0);
 
 
                        /*
                        /*
                         * Temporarily convert region from
                         * Temporarily convert region from
                         * client coords to screen coords, since
                         * client coords to screen coords, since
                         * hwnd->update is kept in screen coords.
                         * hwnd->update is kept in screen coords.
                         */
                         */
                        OffsetRgn(hrgn, hdc->hwnd->clirect.left,
                        OffsetRgn(hrgn, hdc->hwnd->clirect.left,
                                hdc->hwnd->clirect.top);
                                hdc->hwnd->clirect.top);
 
 
                        if(fnMode == RGN_COPY)
                        if(fnMode == RGN_COPY)
                                CombineRgn(newrgn, hrgn, NULL, fnMode);
                                CombineRgn(newrgn, hrgn, NULL, fnMode);
                        else CombineRgn(newrgn, (HRGN)hdc->region, hrgn,fnMode);
                        else CombineRgn(newrgn, (HRGN)hdc->region, hrgn,fnMode);
 
 
                        /* convert passed region back to client coords*/
                        /* convert passed region back to client coords*/
                        OffsetRgn(hrgn, -hdc->hwnd->clirect.left,
                        OffsetRgn(hrgn, -hdc->hwnd->clirect.left,
                                -hdc->hwnd->clirect.top);
                                -hdc->hwnd->clirect.top);
 
 
 
 
                        hrgn = newrgn;
                        hrgn = newrgn;
                }
                }
                DeleteObject((HRGN)hdc->region);
                DeleteObject((HRGN)hdc->region);
                hdc->region = (MWRGNOBJ *)hrgn;
                hdc->region = (MWRGNOBJ *)hrgn;
 
 
                /* force recalc of clipregion*/
                /* force recalc of clipregion*/
                cliphdc = NULL;
                cliphdc = NULL;
                MwPrepareDC(hdc);
                MwPrepareDC(hdc);
        }
        }
        if(hrgn)
        if(hrgn)
                return ((MWRGNOBJ *)hrgn)->rgn->type;
                return ((MWRGNOBJ *)hrgn)->rgn->type;
        return NULLREGION;
        return NULLREGION;
}
}
 
 
/* update region is returned in client coordinates*/
/* update region is returned in client coordinates*/
int WINAPI
int WINAPI
GetUpdateRgn(HWND hwnd, HRGN hrgn, BOOL bErase)
GetUpdateRgn(HWND hwnd, HRGN hrgn, BOOL bErase)
{
{
        /* FIXME bErase*/
        /* FIXME bErase*/
        if(!hwnd)
        if(!hwnd)
                return ERROR;
                return ERROR;
 
 
        /* convert internal update region to client coords*/
        /* convert internal update region to client coords*/
        GdOffsetRegion(hwnd->update, -hwnd->clirect.left, -hwnd->clirect.top);
        GdOffsetRegion(hwnd->update, -hwnd->clirect.left, -hwnd->clirect.top);
        GdCopyRegion(((MWRGNOBJ *)hrgn)->rgn, hwnd->update);
        GdCopyRegion(((MWRGNOBJ *)hrgn)->rgn, hwnd->update);
        GdOffsetRegion(hwnd->update, hwnd->clirect.left, hwnd->clirect.top);
        GdOffsetRegion(hwnd->update, hwnd->clirect.left, hwnd->clirect.top);
        return hwnd->update->type;
        return hwnd->update->type;
}
}
#endif /* UPDATEREGIONS*/
#endif /* UPDATEREGIONS*/
 
 
/* update rectangle is returned in client coords*/
/* update rectangle is returned in client coords*/
BOOL WINAPI
BOOL WINAPI
GetUpdateRect(HWND hwnd, LPRECT lpRect, BOOL bErase)
GetUpdateRect(HWND hwnd, LPRECT lpRect, BOOL bErase)
{
{
        /* FIXME bErase*/
        /* FIXME bErase*/
        if(!hwnd)
        if(!hwnd)
                return FALSE;
                return FALSE;
#if UPDATEREGIONS
#if UPDATEREGIONS
        if(lpRect) {
        if(lpRect) {
                *lpRect = hwnd->update->extents;
                *lpRect = hwnd->update->extents;
                /* convert to client coords*/
                /* convert to client coords*/
                ScreenToClient(hwnd, (LPPOINT)&lpRect->left);
                ScreenToClient(hwnd, (LPPOINT)&lpRect->left);
                ScreenToClient(hwnd, (LPPOINT)&lpRect->right);
                ScreenToClient(hwnd, (LPPOINT)&lpRect->right);
        }
        }
 
 
        /* return TRUE if update region is non-empty*/
        /* return TRUE if update region is non-empty*/
        return hwnd->update->type != NULLREGION;
        return hwnd->update->type != NULLREGION;
#else
#else
        GetClientRect(hwnd, lpRect);
        GetClientRect(hwnd, lpRect);
        return TRUE;
        return TRUE;
#endif
#endif
}
}
 
 
HBRUSH WINAPI
HBRUSH WINAPI
CreateSolidBrush(COLORREF crColor)
CreateSolidBrush(COLORREF crColor)
{
{
        MWBRUSHOBJ *hbr;
        MWBRUSHOBJ *hbr;
 
 
        hbr = GdItemNew(MWBRUSHOBJ);
        hbr = GdItemNew(MWBRUSHOBJ);
        if(!hbr)
        if(!hbr)
                return NULL;
                return NULL;
        hbr->hdr.type = OBJ_BRUSH;
        hbr->hdr.type = OBJ_BRUSH;
        hbr->hdr.stockobj = FALSE;
        hbr->hdr.stockobj = FALSE;
        hbr->style = BS_SOLID;
        hbr->style = BS_SOLID;
        hbr->color = crColor;
        hbr->color = crColor;
        return (HBRUSH)hbr;
        return (HBRUSH)hbr;
}
}
 
 
HPEN WINAPI
HPEN WINAPI
CreatePen(int nPenStyle, int nWidth, COLORREF crColor)
CreatePen(int nPenStyle, int nWidth, COLORREF crColor)
{
{
        MWPENOBJ *hpen;
        MWPENOBJ *hpen;
 
 
        /* fix: nWidth > 1*/
        /* fix: nWidth > 1*/
        hpen = GdItemNew(MWPENOBJ);
        hpen = GdItemNew(MWPENOBJ);
        if(!hpen)
        if(!hpen)
                return NULL;
                return NULL;
        hpen->hdr.type = OBJ_PEN;
        hpen->hdr.type = OBJ_PEN;
        hpen->hdr.stockobj = FALSE;
        hpen->hdr.stockobj = FALSE;
        hpen->style = nPenStyle;
        hpen->style = nPenStyle;
        hpen->color = crColor;
        hpen->color = crColor;
        return (HPEN)hpen;
        return (HPEN)hpen;
}
}
 
 
HBITMAP WINAPI
HBITMAP WINAPI
CreateCompatibleBitmap(HDC hdc, int nWidth, int nHeight)
CreateCompatibleBitmap(HDC hdc, int nWidth, int nHeight)
{
{
        MWBITMAPOBJ *   hbitmap;
        MWBITMAPOBJ *   hbitmap;
        int             size;
        int             size;
        int             linelen;
        int             linelen;
 
 
        if(!hdc)
        if(!hdc)
                return NULL;
                return NULL;
 
 
        nWidth = MWMAX(nWidth, 1);
        nWidth = MWMAX(nWidth, 1);
        nHeight = MWMAX(nHeight, 1);
        nHeight = MWMAX(nHeight, 1);
 
 
        /* calc memory allocation size and linelen from width and height*/
        /* calc memory allocation size and linelen from width and height*/
        if(!GdCalcMemGCAlloc(hdc->psd, nWidth, nHeight, 0, 0, &size, &linelen))
        if(!GdCalcMemGCAlloc(hdc->psd, nWidth, nHeight, 0, 0, &size, &linelen))
                return NULL;
                return NULL;
 
 
        /* allocate gdi object*/
        /* allocate gdi object*/
        hbitmap = (MWBITMAPOBJ *)GdItemAlloc(sizeof(MWBITMAPOBJ)-1+size);
        hbitmap = (MWBITMAPOBJ *)GdItemAlloc(sizeof(MWBITMAPOBJ)-1+size);
        if(!hbitmap)
        if(!hbitmap)
                return NULL;
                return NULL;
        hbitmap->hdr.type = OBJ_BITMAP;
        hbitmap->hdr.type = OBJ_BITMAP;
        hbitmap->hdr.stockobj = FALSE;
        hbitmap->hdr.stockobj = FALSE;
        hbitmap->width = nWidth;
        hbitmap->width = nWidth;
        hbitmap->height = nHeight;
        hbitmap->height = nHeight;
 
 
        /* create compatible with hdc*/
        /* create compatible with hdc*/
        hbitmap->planes = hdc->psd->planes;
        hbitmap->planes = hdc->psd->planes;
        hbitmap->bpp = hdc->psd->bpp;
        hbitmap->bpp = hdc->psd->bpp;
        hbitmap->linelen = linelen;
        hbitmap->linelen = linelen;
        hbitmap->size = size;
        hbitmap->size = size;
 
 
        return (HBRUSH)hbitmap;
        return (HBRUSH)hbitmap;
}
}
 
 
/* return NULL if no driver bitblit available*/
/* return NULL if no driver bitblit available*/
HDC WINAPI
HDC WINAPI
CreateCompatibleDC(HDC hdc)
CreateCompatibleDC(HDC hdc)
{
{
        HDC     hdcmem;
        HDC     hdcmem;
        PSD     psd;
        PSD     psd;
        PSD     mempsd;
        PSD     mempsd;
 
 
        /* allow NULL hdc to mean screen*/
        /* allow NULL hdc to mean screen*/
        psd = hdc? hdc->psd: &scrdev;
        psd = hdc? hdc->psd: &scrdev;
 
 
        /* allocate memory device, if driver doesn't blit will fail*/
        /* allocate memory device, if driver doesn't blit will fail*/
        mempsd = psd->AllocateMemGC(psd);
        mempsd = psd->AllocateMemGC(psd);
        if(!mempsd)
        if(!mempsd)
                return NULL;
                return NULL;
 
 
        /* allocate a DC for DesktopWindow*/
        /* allocate a DC for DesktopWindow*/
        hdcmem = GetDCEx(NULL, NULL, DCX_DEFAULTCLIP);
        hdcmem = GetDCEx(NULL, NULL, DCX_DEFAULTCLIP);
        if(!hdcmem) {
        if(!hdcmem) {
                mempsd->FreeMemGC(mempsd);
                mempsd->FreeMemGC(mempsd);
                return NULL;
                return NULL;
        }
        }
        hdcmem->psd = mempsd;
        hdcmem->psd = mempsd;
 
 
        /* select in default bitmap to setup mem device parms*/
        /* select in default bitmap to setup mem device parms*/
        SelectObject(hdcmem, (HGDIOBJ)&default_bitmap);
        SelectObject(hdcmem, (HGDIOBJ)&default_bitmap);
        return hdcmem;
        return hdcmem;
}
}
 
 
BOOL WINAPI
BOOL WINAPI
BitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
BitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
        HDC hdcSrc, int nXSrc, int nYSrc, DWORD dwRop)
        HDC hdcSrc, int nXSrc, int nYSrc, DWORD dwRop)
{
{
        /* use stretch blit with equal src and dest width/height*/
        /* use stretch blit with equal src and dest width/height*/
        return StretchBlt(hdcDest, nXDest, nYDest, nWidth, nHeight,
        return StretchBlt(hdcDest, nXDest, nYDest, nWidth, nHeight,
                hdcSrc, nXSrc, nYSrc, nWidth, nHeight, dwRop);
                hdcSrc, nXSrc, nYSrc, nWidth, nHeight, dwRop);
}
}
 
 
BOOL WINAPI
BOOL WINAPI
StretchBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest,
StretchBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest,
        int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
        int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
        int nWidthSrc, int nHeightSrc, DWORD dwRop)
        int nWidthSrc, int nHeightSrc, DWORD dwRop)
{
{
 
 
        HWND    hwnd;
        HWND    hwnd;
        POINT   dst, src;
        POINT   dst, src;
 
 
        if(!hdcDest || !hdcSrc)
        if(!hdcDest || !hdcSrc)
                return FALSE;
                return FALSE;
        dst.x = nXOriginDest;
        dst.x = nXOriginDest;
        dst.y = nYOriginDest;
        dst.y = nYOriginDest;
        src.x = nXOriginSrc;
        src.x = nXOriginSrc;
        src.y = nYOriginSrc;
        src.y = nYOriginSrc;
 
 
        /* if src screen DC, convert coords*/
        /* if src screen DC, convert coords*/
        /* FIXME: src clipping isn't checked, only one set of cliprects also*/
        /* FIXME: src clipping isn't checked, only one set of cliprects also*/
        if(!MwIsMemDC(hdcSrc) && MwIsClientDC(hdcSrc)) {
        if(!MwIsMemDC(hdcSrc) && MwIsClientDC(hdcSrc)) {
                if(!(hwnd = MwPrepareDC(hdcSrc)))
                if(!(hwnd = MwPrepareDC(hdcSrc)))
                        return FALSE;
                        return FALSE;
                ClientToScreen(hwnd, &src);
                ClientToScreen(hwnd, &src);
        }
        }
        /* if dst screen DC, convert coords and set clipping*/
        /* if dst screen DC, convert coords and set clipping*/
        /* FIXME: if dest is also screen, src clipping will be overwritten*/
        /* FIXME: if dest is also screen, src clipping will be overwritten*/
        if(!MwIsMemDC(hdcDest) && MwIsClientDC(hdcDest)) {
        if(!MwIsMemDC(hdcDest) && MwIsClientDC(hdcDest)) {
                if(!(hwnd = MwPrepareDC(hdcDest)))
                if(!(hwnd = MwPrepareDC(hdcDest)))
                        return FALSE;
                        return FALSE;
                ClientToScreen(hwnd, &dst);
                ClientToScreen(hwnd, &dst);
        }
        }
 
 
        if (nWidthDest == nWidthSrc && nHeightDest == nHeightSrc) {
        if (nWidthDest == nWidthSrc && nHeightDest == nHeightSrc) {
                GdBlit(hdcDest->psd, dst.x, dst.y, nWidthDest, nHeightDest,
                GdBlit(hdcDest->psd, dst.x, dst.y, nWidthDest, nHeightDest,
                        hdcSrc->psd, src.x, src.y, dwRop);
                        hdcSrc->psd, src.x, src.y, dwRop);
        } else {
        } else {
                GdStretchBlit(hdcDest->psd, dst.x, dst.y,
                GdStretchBlit(hdcDest->psd, dst.x, dst.y,
                        nWidthDest, nHeightDest, hdcSrc->psd, src.x, src.y,
                        nWidthDest, nHeightDest, hdcSrc->psd, src.x, src.y,
                        nWidthSrc, nHeightSrc, dwRop);
                        nWidthSrc, nHeightSrc, dwRop);
        }
        }
        return TRUE;
        return TRUE;
}
}
 
 
UINT WINAPI
UINT WINAPI
GetSystemPaletteEntries(HDC hdc,UINT iStartIndex,UINT nEntries,
GetSystemPaletteEntries(HDC hdc,UINT iStartIndex,UINT nEntries,
        LPPALETTEENTRY lppe)
        LPPALETTEENTRY lppe)
{
{
        UINT            i;
        UINT            i;
        MWPALENTRY      rgb;
        MWPALENTRY      rgb;
 
 
        /* currently, we only work for screen device*/
        /* currently, we only work for screen device*/
        if(!hdc || hdc->psd != &scrdev)
        if(!hdc || hdc->psd != &scrdev)
                return 0;
                return 0;
 
 
        for(i=0; i<nEntries; ++i) {
        for(i=0; i<nEntries; ++i) {
                if(!GdGetPalette(hdc->psd, i+iStartIndex, 1, &rgb))
                if(!GdGetPalette(hdc->psd, i+iStartIndex, 1, &rgb))
                        break;
                        break;
                lppe->peRed = rgb.r;
                lppe->peRed = rgb.r;
                lppe->peGreen = rgb.g;
                lppe->peGreen = rgb.g;
                lppe->peBlue = rgb.b;
                lppe->peBlue = rgb.b;
                lppe->peFlags = 0;
                lppe->peFlags = 0;
                ++lppe;
                ++lppe;
        }
        }
        return i;
        return i;
}
}
 
 
/* allow NULL hdc for scrdev*/
/* allow NULL hdc for scrdev*/
int WINAPI
int WINAPI
GetDeviceCaps(HDC hdc, int nIndex)
GetDeviceCaps(HDC hdc, int nIndex)
{
{
        PSD     psd;
        PSD     psd;
 
 
        if (!hdc)
        if (!hdc)
                psd = &scrdev;
                psd = &scrdev;
        else psd = hdc->psd;
        else psd = hdc->psd;
 
 
        switch(nIndex) {
        switch(nIndex) {
        case HORZRES:
        case HORZRES:
                return psd->xvirtres;
                return psd->xvirtres;
        case VERTRES:
        case VERTRES:
                return psd->yvirtres;
                return psd->yvirtres;
        case BITSPIXEL:
        case BITSPIXEL:
                return psd->bpp;
                return psd->bpp;
        case PLANES:
        case PLANES:
                return psd->planes;
                return psd->planes;
        case LOGPIXELSX:
        case LOGPIXELSX:
        case LOGPIXELSY:
        case LOGPIXELSY:
                return 96;
                return 96;
        case SIZEPALETTE:
        case SIZEPALETTE:
                if (psd->bpp <= 8)
                if (psd->bpp <= 8)
                        return psd->ncolors;
                        return psd->ncolors;
                break;
                break;
        }
        }
        return 0;
        return 0;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.