]> git.saurik.com Git - wxWidgets.git/blobdiff - src/xpm/scan.c
Corrected wxScrolledWindow's OnSize behaviour.
[wxWidgets.git] / src / xpm / scan.c
index eabbde11586292d6228d97fa85d646783db1d5cb..f5e61bb78df26043c069793d643cf12a57ebad60 100644 (file)
@@ -96,26 +96,40 @@ LFUNC(AGetImagePixels, int, (XImage *image, unsigned int width,
                             int (*storeFunc) ()));
 # endif/* AMIGA */
 #else  /* ndef FOR_MSW */
+
+#if defined(__OS2__) && defined(__VISAGECPP30__)
+LFUNC(MSWGetImagePixels, int, (Display* display, XImage* image, unsigned int width,
+                               unsigned int height, PixelsMap* pmap,
+                               int (*storeFunc) (Pixel, PixelsMap*, unsigned int*)));
+#else
 LFUNC(MSWGetImagePixels, int, (Display *d, XImage *image, unsigned int width,
-                              unsigned int height, PixelsMap *pmap,
-                              int (*storeFunc) ()));
+                   unsigned int height, PixelsMap *pmap,
+                   int (*storeFunc) ()));
+#endif
+
 #endif
+
 LFUNC(ScanTransparentColor, int, (XpmColor *color, unsigned int cpp,
-                                 XpmAttributes *attributes));
+                  XpmAttributes *attributes));
 
 LFUNC(ScanOtherColors, int, (Display *display, XpmColor *colors, int ncolors,
-                            Pixel *pixels, unsigned int mask,
-                            unsigned int cpp, XpmAttributes *attributes));
+                 Pixel *pixels, unsigned int mask,
+                 unsigned int cpp, XpmAttributes *attributes));
 
 /*
  * This function stores the given pixel in the given arrays which are grown
  * if not large enough.
  */
+#ifdef __OS2__
+/* Visual Age cannot deal with old, non-ansi, code */
+static int storePixel(Pixel pixel, PixelsMap* pmap, unsigned int* index_return)
+#else
 static int
 storePixel(pixel, pmap, index_return)
     Pixel pixel;
     PixelsMap *pmap;
     unsigned int *index_return;
+#endif
 {
     unsigned int i;
     Pixel *p;
@@ -146,11 +160,16 @@ storePixel(pixel, pmap, index_return)
     return 0;
 }
 
+#ifdef __OS2__
+/* Visual Age cannot deal with old, non-ansi, code */
+static int storeMaskPixel(Pixel pixel, PixelsMap* pmap, unsigned int* index_return)
+#else
 static int
 storeMaskPixel(pixel, pmap, index_return)
     Pixel pixel;
     PixelsMap *pmap;
     unsigned int *index_return;
+#endif
 {
     if (!pixel) {
        if (!pmap->ncolors) {
@@ -176,6 +195,16 @@ storeMaskPixel(pixel, pmap, index_return)
  * This function scans the given image and stores the found informations in
  * the given XpmImage structure.
  */
+#ifdef __OS2__
+/* Visual Age cannot deal with old, non-ansi, code */
+int XpmCreateXpmImageFromImage(
+  Display*       display
+, XImage*        image
+, XImage*        shapeimage
+, XpmImage*      xpmimage
+, XpmAttributes* attributes
+)
+#else
 int
 XpmCreateXpmImageFromImage(display, image, shapeimage,
                           xpmimage, attributes)
@@ -184,6 +213,7 @@ XpmCreateXpmImageFromImage(display, image, shapeimage,
     XImage *shapeimage;
     XpmImage *xpmimage;
     XpmAttributes *attributes;
+#endif
 {
     /* variables stored in the XpmAttributes structure */
     unsigned int cpp;
@@ -240,57 +270,67 @@ XpmCreateXpmImageFromImage(display, image, shapeimage,
     /*
      * scan shape mask if any
      */
-    if (shapeimage) {
+    if (shapeimage)
+    {
 #ifndef FOR_MSW
 # ifndef AMIGA
-       ErrorStatus = GetImagePixels1(shapeimage, width, height, &pmap,
-                                     storeMaskPixel);
+           ErrorStatus = GetImagePixels1(shapeimage, width, height, &pmap,
+                                     storeMaskPixel);
 # else
-       ErrorStatus = AGetImagePixels(shapeimage, width, height, &pmap,
-                                     storeMaskPixel);
-# endif
+           ErrorStatus = AGetImagePixels(shapeimage, width, height, &pmap,
+                                     storeMaskPixel);
+# endif /* AMIGA */
 #else
-       ErrorStatus = MSWGetImagePixels(display, shapeimage, width, height,
-                                       &pmap, storeMaskPixel);
-#endif
+
+           ErrorStatus = MSWGetImagePixels(display, shapeimage, width, height,
+                                       &pmap, storeMaskPixel);
+
+#endif /* ndef for FOR_MSW */
+
        if (ErrorStatus != XpmSuccess)
            RETURN(ErrorStatus);
     }
 
     /*
      * scan the image data
-     * 
+     *
      * In case depth is 1 or bits_per_pixel is 4, 6, 8, 24 or 32 use optimized
      * functions, otherwise use slower but sure general one.
-     * 
+     *
      */
 
-    if (image) {
+    if (image)
+    {
 #ifndef FOR_MSW
 # ifndef AMIGA
-       if (((image->bits_per_pixel | image->depth) == 1)  &&
-           (image->byte_order == image->bitmap_bit_order))
-           ErrorStatus = GetImagePixels1(image, width, height, &pmap,
-                                         storePixel);
-       else if (image->format == ZPixmap) {
-           if (image->bits_per_pixel == 8)
-               ErrorStatus = GetImagePixels8(image, width, height, &pmap);
-           else if (image->bits_per_pixel == 16)
-               ErrorStatus = GetImagePixels16(image, width, height, &pmap);
-           else if (image->bits_per_pixel == 32)
-               ErrorStatus = GetImagePixels32(image, width, height, &pmap);
-       } else
-           ErrorStatus = GetImagePixels(image, width, height, &pmap);
+           if (((image->bits_per_pixel | image->depth) == 1)  &&
+               (image->byte_order == image->bitmap_bit_order))
+           ErrorStatus = GetImagePixels1(image, width, height, &pmap,
+                                         storePixel);
+           else if (image->format == ZPixmap)
+       {
+               if (image->bits_per_pixel == 8)
+                   ErrorStatus = GetImagePixels8(image, width, height, &pmap);
+               else if (image->bits_per_pixel == 16)
+                       ErrorStatus = GetImagePixels16(image, width, height, &pmap);
+           else if (image->bits_per_pixel == 32)
+                       ErrorStatus = GetImagePixels32(image, width, height, &pmap);
+       }
+           else
+               ErrorStatus = GetImagePixels(image, width, height, &pmap);
 # else
-       ErrorStatus = AGetImagePixels(image, width, height, &pmap,
-                                     storePixel);
-# endif
+           ErrorStatus = AGetImagePixels(image, width, height, &pmap,
+                                     storePixel);
+# endif /* AMIGA */
 #else
-       ErrorStatus = MSWGetImagePixels(display, image, width, height, &pmap,
-                                       storePixel);
+
+           ErrorStatus = MSWGetImagePixels(display, image, width, height, &pmap,
+                                       storePixel);
+
 #endif
-       if (ErrorStatus != XpmSuccess)
-           RETURN(ErrorStatus);
+
+           if (ErrorStatus != XpmSuccess)
+               RETURN(ErrorStatus);
     }
 
     /*
@@ -345,11 +385,16 @@ error:
     return (ErrorStatus);
 }
 
+#ifdef __OS2__
+/* Visual Age cannot deal with old, non-ansi, code */
+static int ScanTransparentColor(XpmColor* color, unsigned int cpp, XpmAttributes* attributes)
+#else
 static int
 ScanTransparentColor(color, cpp, attributes)
     XpmColor *color;
     unsigned int cpp;
     XpmAttributes *attributes;
+#endif
 {
     char *s;
     unsigned int a, b, c;
@@ -399,6 +444,18 @@ ScanTransparentColor(color, cpp, attributes)
     return (XpmSuccess);
 }
 
+#ifdef __OS2__
+/* Visual Age cannot deal with old, non-ansi, code */
+static int ScanOtherColors(
+  Display*       display
+, XpmColor*      colors
+, int            ncolors
+, Pixel*         pixels
+, unsigned int   mask
+, unsigned int   cpp
+, XpmAttributes* attributes
+)
+#else
 static int
 ScanOtherColors(display, colors, ncolors, pixels, mask, cpp, attributes)
     Display *display;
@@ -408,6 +465,7 @@ ScanOtherColors(display, colors, ncolors, pixels, mask, cpp, attributes)
     unsigned int mask;
     unsigned int cpp;
     XpmAttributes *attributes;
+#endif
 {
     /* variables stored in the XpmAttributes structure */
     Colormap colormap;
@@ -416,8 +474,8 @@ ScanOtherColors(display, colors, ncolors, pixels, mask, cpp, attributes)
 #ifndef FOR_MSW
     xpmRgbName rgbn[MAX_RGBNAMES];
 #else
-    xpmRgbName *rgbn = NULL; 
-#endif    
+    xpmRgbName *rgbn = NULL;
+#endif
     int rgbn_max = 0;
     unsigned int i, j, c, i2;
     XpmColor *color;
@@ -452,7 +510,7 @@ ScanOtherColors(display, colors, ncolors, pixels, mask, cpp, attributes)
        return (XpmNoMemory);
 
     for (i = 0, i2 = mask, color = colors, xcolor = xcolors;
-        i < ncolors; i++, i2++, color++, xcolor++, pixels++) {
+        i < (unsigned)ncolors; i++, i2++, color++, xcolor++, pixels++) {
 
        if (!(s = color->string = (char *) XpmMalloc(cpp + 1))) {
            XpmFree(xcolors);
@@ -465,7 +523,11 @@ ScanOtherColors(display, colors, ncolors, pixels, mask, cpp, attributes)
 
        xcolor->pixel = *pixels;
     }
+#ifdef __OS2__
+    XQueryColors(display, &colormap, xcolors, ncolors);
+#else
     XQueryColors(display, colormap, xcolors, ncolors);
+#endif
 
 #ifndef FOR_MSW
     /* read the rgb file if any was specified */
@@ -491,7 +553,7 @@ ScanOtherColors(display, colors, ncolors, pixels, mask, cpp, attributes)
     }
 /* end 3.2 bc */
 
-    for (i = 0, color = colors, xcolor = xcolors; i < ncolors;
+    for (i = 0, color = colors, xcolor = xcolors; i < (unsigned)ncolors;
                                                  i++, color++, xcolor++) {
 
        /* look for related info from the attributes if any */
@@ -540,10 +602,10 @@ ScanOtherColors(display, colors, ncolors, pixels, mask, cpp, attributes)
 #ifndef FOR_MSW
                sprintf(buf, "#%04X%04X%04X",
                        xcolor->red, xcolor->green, xcolor->blue);
-#else   
+#else
                sprintf(buf, "#%02x%02x%02x",
                        xcolor->red, xcolor->green, xcolor->blue);
-#endif                 
+#endif
                color->c_color = (char *) xpmstrdup(buf);
            }
            if (!color->c_color) {
@@ -902,15 +964,15 @@ AGetImagePixels (
     unsigned int    x, y;
     unsigned char  *pixels;
     XImage         *tmp_img;
-    
+
     pixels = XpmMalloc ((((width+15)>>4)<<4)*sizeof (*pixels));
     if (pixels == NULL)
        return XpmNoMemory;
-    
+
     tmp_img = AllocXImage ((((width+15)>>4)<<4), 1, image->rp->BitMap->Depth);
     if (tmp_img == NULL)
        CLEAN_UP (XpmNoMemory)
-    
+
     iptr = pmap->pixelindex;
     for (y = 0; y < height; ++y)
     {
@@ -921,7 +983,7 @@ AGetImagePixels (
                CLEAN_UP (XpmNoMemory)
        }
     }
-    
+
     CLEAN_UP (XpmSuccess)
 }
 
@@ -929,6 +991,30 @@ AGetImagePixels (
 
 # endif/* AMIGA */
 #else  /* ndef FOR_MSW */
+
+#ifdef __OS2__
+
+#ifdef __VISAGECPP30__
+static int MSWGetImagePixels(
+  Display*     display
+, XImage*      image
+, unsigned int width
+, unsigned int height
+, PixelsMap*   pmap
+, int          (*storeFunc) (Pixel, PixelsMap*, unsigned int*)
+)
+#else
+static int MSWGetImagePixels(
+  Display*     display
+, XImage*      image
+, unsigned int width
+, unsigned int height
+, PixelsMap*   pmap
+, int          (*storeFunc) ()
+)
+#endif
+
+#else
 static int
 MSWGetImagePixels(display, image, width, height, pmap, storeFunc)
     Display *display;
@@ -937,17 +1023,39 @@ MSWGetImagePixels(display, image, width, height, pmap, storeFunc)
     unsigned int height;
     PixelsMap *pmap;
     int (*storeFunc) ();
+#endif
 {
     unsigned int *iptr;
     unsigned int x, y;
     Pixel pixel;
+#ifdef __OS2__
+     HAB          hab = WinQueryAnchorBlock(HWND_DESKTOP);
+     HDC          shapedc;
+     DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+     SIZEL        sizl = {0, 0};
+     POINTL       point;
+#endif
 
     iptr = pmap->pixelindex;
 
+#ifdef __OS2__
+    shapedc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
+    *display = GpiCreatePS(hab, shapedc, &sizl, GPIA_ASSOC | PU_PELS);
+    GpiSetBitmap(*display, image->bitmap);
+#else
     SelectObject(*display, image->bitmap);
+#endif
+
     for (y = 0; y < height; y++) {
        for (x = 0; x < width; x++, iptr++) {
+#ifdef __OS2__
+     point.x = x;
+     point.y = y;
+     pixel = GpiQueryPel(*display, &point);
+#else
            pixel = GetPixel(*display, x, y);
+#endif
+
            if ((*storeFunc) (pixel, pmap, iptr))
                return (XpmNoMemory);
        }