Implement SelectPalette and RealizePalette in mfdrv

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





ChangeLog:

     Implementation of SelectPalette and RealizePalette
     in Metafile driver.

Warren Baird : Warren_Baird@cimmetry.com
Dave Belanger

diff -ur clean/wine/dlls/gdi/mfdrv/objects.c   wine/dlls/gdi/mfdrv/objects.c
--- clean/wine/dlls/gdi/mfdrv/objects.c  Wed Jan 29 15:30:25 2003
+++ wine/dlls/gdi/mfdrv/objects.c  Fri Jan 31 12:32:31 2003
@@ -234,3 +234,89 @@
     if (MFDRV_CreatePenIndirect( dev, hpen, &logpen )) return hpen;
     return 0;
 }
+
+
+/******************************************************************
+ *         MFDRV_CreatePalette
+ */
+static BOOL MFDRV_CreatePalette(PHYSDEV dev, HPALETTE hPalette, LOGPALETTE*
logPalette, int sizeofPalette)
+{
+    int index;
+    char buffer[sizeof(METARECORD) + sizeofPalette - sizeof(WORD)];
+    METARECORD *mr = (METARECORD *)&buffer;
+
+    mr->rdSize = (sizeof(METARECORD) + sizeofPalette - sizeof(WORD)) /
sizeof(WORD);
+    mr->rdFunction = META_CREATEPALETTE;
+    memcpy(&(mr->rdParm), logPalette, sizeofPalette);
+    if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * sizeof(WORD)))) return
FALSE;
+
+    mr->rdSize = sizeof(METARECORD) / sizeof(WORD);
+    mr->rdFunction = META_SELECTPALETTE;
+
+    if ((index = MFDRV_AddHandleDC( dev )) == -1) return FALSE;
+    *(mr->rdParm) = index;
+    return MFDRV_WriteRecord( dev, mr, mr->rdSize * sizeof(WORD));
+}
+
+
+/***********************************************************************
+ *           MFDRV_SelectPalette
+ */
+HPALETTE MFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPalette, BOOL
bForceBackground )
+{
+#define PALVERSION 0x0300
+
+    PLOGPALETTE logPalette = NULL;
+    WORD        wNumEntries = 0;
+    BOOL        creationSucceed = FALSE;
+    int         sizeofPalette;
+
+    GetObjectA(hPalette, sizeof(WORD), (LPSTR) &wNumEntries);
+
+    if (wNumEntries == 0) {
+         return 0;
+    }
+
+    sizeofPalette = sizeof(LOGPALETTE) + ((wNumEntries-1) *
sizeof(PALETTEENTRY));
+    logPalette = (LPLOGPALETTE)malloc(sizeofPalette);
+
+    if (logPalette == NULL) {
+         return 0;
+    }
+
+    logPalette->palVersion   = PALVERSION;
+    logPalette->palNumEntries = wNumEntries;
+
+    GetPaletteEntries(hPalette, 0, wNumEntries, logPalette->palPalEntry);
+
+    creationSucceed = MFDRV_CreatePalette( dev, hPalette, logPalette,
sizeofPalette );
+
+    free(logPalette);
+
+    if (creationSucceed)
+      return hPalette;
+
+    return 0;
+}
+
+/***********************************************************************
+ *           MFDRV_RealizePalette
+ */
+UINT MFDRV_RealizePalette(PHYSDEV dev, HPALETTE hPalette, BOOL dummy)
+{
+    char buffer[sizeof(METARECORD) - sizeof(WORD)];
+    METARECORD *mr = (METARECORD *)&buffer;
+
+    mr->rdSize = (sizeof(METARECORD) - sizeof(WORD)) / sizeof(WORD);
+    mr->rdFunction = META_REALIZEPALETTE;
+
+    if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * sizeof(WORD)))) return 0;
+
+    /* The return value is suppose to be the number of entries
+       in the logical palette mapped to the system palette or 0
+       if the function failed. Since it's not trivial here to
+       get that kind of information and since it's of little
+       use in the case of metafiles, we'll always return 1. */
+
+    return 1;
+}

diff -ur clean/wine/dlls/gdi/mfdrv/metafiledrv.h
wine/dlls/gdi/mfdrv/metafiledrv.h
--- clean/wine/dlls/gdi/mfdrv/metafiledrv.h   Wed Jan 29 15:30:25 2003
+++ wine/dlls/gdi/mfdrv/metafiledrv.h    Fri Jan 31 12:40:36 2003
@@ -117,6 +117,8 @@
 extern BOOL MFDRV_SelectClipPath( PHYSDEV dev, INT iMode );
 extern HFONT MFDRV_SelectFont( PHYSDEV dev, HFONT handle );
 extern HPEN MFDRV_SelectPen( PHYSDEV dev, HPEN handle );
+HPALETTE MFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPalette, BOOL
bForceBackground);
+UINT     MFDRV_RealizePalette(PHYSDEV dev, HPALETTE hPalette, BOOL);
 extern COLORREF MFDRV_SetBkColor( PHYSDEV dev, COLORREF color );
 extern INT MFDRV_SetBkMode( PHYSDEV dev, INT mode );
 extern INT MFDRV_SetMapMode( PHYSDEV dev, INT mode );

diff -ur clean/wine/dlls/gdi/mfdrv/init.c  wine/dlls/gdi/mfdrv/init.c
--- clean/wine/dlls/gdi/mfdrv/init.c     Wed Jan 29 15:30:25 2003
+++ wine/dlls/gdi/mfdrv/init.c     Fri Jan 31 12:45:02 2003
@@ -95,7 +95,7 @@
     MFDRV_Polyline,                  /* pPolyline */
     NULL,                            /* pPolylineTo */
     NULL,                            /* pRealizeDefaultPalette */
-    NULL,                            /* pRealizePalette */
+    MFDRV_RealizePalette,            /* pRealizePalette */
     MFDRV_Rectangle,                 /* pRectangle */
     NULL,                            /* pResetDC */
     MFDRV_RestoreDC,                 /* pRestoreDC */
@@ -107,7 +107,7 @@
     MFDRV_SelectBrush,               /* pSelectBrush */
     MFDRV_SelectClipPath,            /* pSelectClipPath */
     MFDRV_SelectFont,                /* pSelectFont */
-    NULL,                            /* pSelectPalette */
+    MFDRV_SelectPalette,             /* pSelectPalette */
     MFDRV_SelectPen,                 /* pSelectPen */
     NULL,                            /* pSetBitmapBits */
     MFDRV_SetBkColor,                /* pSetBkColor */

diff -ur clean/wine/objects/palette.c   wine/objects/palette.c
--- clean/wine/objects/palette.c   Wed Jan 29 15:31:13 2003
+++ wine/objects/palette.c    Fri Jan 31 12:47:21 2003
@@ -674,6 +674,7 @@
     }
     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
     prev = dc->hPalette;
+    if (dc->funcs->pSelectPalette) hpal = dc->funcs->pSelectPalette(
dc->physDev, hpal, FALSE );
     dc->hPalette = hpal;
     GDI_ReleaseObj( hdc );
     if (!wBkg) hPrimaryPalette = hpal;




[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux