home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / XfeTest / TestPixmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.5 KB  |  211 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*-----------------------------------------*/
  19. /*                                                                        */
  20. /* Name:        <XfeTest/TestPixmap.c>                                    */
  21. /* Description:    Xfe widget pixmap test funcs.                            */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeTest.h>
  28.  
  29. #if defined(LINUX) || defined(IRIX)
  30. #include <X11/xpm.h>
  31. #else
  32. #include <xpm.h>
  33. #endif
  34.  
  35. /*----------------------------------------------------------------------*/
  36. Boolean
  37. XfeAllocatePixmapFromFile(char *            filename,
  38.                           Display *            dpy,
  39.                           Drawable            d,
  40.                           Colormap            colormap,
  41.                           Cardinal            closeness,
  42.                           Cardinal            depth,
  43.                           Pixel                bg,
  44.                           Pixmap *            pixmap,
  45.                           Pixmap *            mask)
  46. {
  47.     XpmAttributes        attrib;
  48.     Boolean                result = True;
  49.     XpmColorSymbol        symbols[1];
  50.  
  51.     assert( dpy != NULL );
  52.     assert( d != None );
  53.     assert( colormap != None );
  54.     assert( pixmap != NULL );
  55.     assert( mask != NULL );
  56.     assert( depth > 0 );
  57.     assert( filename != NULL );
  58.     assert( access(filename,F_OK | R_OK) == 0 );
  59.  
  60.     /*  Set up the transparent symbol */
  61.     symbols[0].name        = NULL;
  62.     symbols[0].value    = "none";
  63.     symbols[0].pixel    = bg;
  64.  
  65.     /* Set up the Xfem Attributes mask and strucutre */
  66.     attrib.valuemask = 
  67.         XpmCloseness | XpmDepth | XpmColormap | XpmColorSymbols;
  68.  
  69.     attrib.colorsymbols        = symbols;
  70.     attrib.numsymbols        = 1;
  71.     attrib.closeness        = closeness;
  72.     attrib.colormap            = colormap;
  73.     attrib.depth            = depth;
  74.  
  75.     /* Try to read the xpm file */
  76.     if (XpmReadFileToPixmap(dpy,d,filename,pixmap,mask,&attrib) != XpmSuccess)
  77.     {
  78.         *pixmap = XmUNSPECIFIED_PIXMAP;
  79.         *mask = XmUNSPECIFIED_PIXMAP;
  80.         
  81.         result = False;
  82.     }
  83.  
  84.     return result;
  85. }
  86. /*----------------------------------------------------------------------*/
  87. Boolean
  88. XfeAllocatePixmapFromData(char **            data,
  89.                           Display *            dpy,
  90.                           Drawable            d,
  91.                           Colormap            colormap,
  92.                           Cardinal            closeness,
  93.                           Cardinal            depth,
  94.                           Pixel                bg,
  95.                           Pixmap *            pixmap,
  96.                           Pixmap *            mask)
  97. {
  98.     XpmAttributes        attrib;
  99.     Boolean                result = True;
  100.     XpmColorSymbol        symbols[1];
  101.  
  102.     assert( dpy != NULL );
  103.     assert( d != None );
  104.     assert( colormap != None );
  105.     assert( pixmap != NULL );
  106.     assert( mask != NULL );
  107.     assert( depth > 0 );
  108.     assert( data != NULL );
  109.  
  110.     /*  Set up the transparent symbol */
  111.     symbols[0].name        = NULL;
  112.     symbols[0].value    = "none";
  113.     symbols[0].pixel    = bg;
  114.  
  115.     /* Set up the Xfem Attributes mask and strucutre */
  116.     attrib.valuemask = 
  117.         XpmCloseness | XpmDepth | XpmColormap | XpmColorSymbols;
  118.     
  119.     attrib.colorsymbols        = symbols;
  120.     attrib.numsymbols        = 1;
  121.     attrib.closeness        = closeness;
  122.     attrib.colormap            = colormap;
  123.     attrib.depth            = depth;
  124.  
  125.     if (XpmCreatePixmapFromData(dpy,d,data,pixmap,mask,&attrib) != XpmSuccess)
  126.     {
  127.         *pixmap = XmUNSPECIFIED_PIXMAP;
  128.         *mask = XmUNSPECIFIED_PIXMAP;
  129.         
  130.         result = False;
  131.     }
  132.  
  133.     return result;
  134. }
  135. /*----------------------------------------------------------------------*/
  136. Pixmap
  137. XfeGetPixmapFromFile(Widget w,char * filename)
  138. {
  139.     Pixmap pixmap = XmUNSPECIFIED_PIXMAP;
  140.     Pixmap mask;
  141.  
  142.     assert( filename != NULL );
  143.     assert( 0 );
  144.  
  145.     XfeAllocatePixmapFromFile(filename,
  146.                               XtDisplay(w),
  147.                               DefaultRootWindow(XtDisplay(w)),
  148.                               XfeColormap(w),
  149.                               40000,
  150.                               XfeDepth(w),
  151.                               XfeBackground(w),
  152.                               &pixmap,
  153.                               &mask);
  154.     
  155.     if (XfePixmapGood(mask))
  156.     {
  157.         XFreePixmap(XtDisplay(w),mask);
  158.     }
  159.     
  160.     return pixmap;
  161. }
  162. /*----------------------------------------------------------------------*/
  163. Pixmap
  164. XfeGetPixmapFromData(Widget w,char ** data)
  165. {
  166.     Pixmap pixmap = XmUNSPECIFIED_PIXMAP;
  167.     Pixmap mask;
  168.  
  169.     assert( data != NULL );
  170. /*     assert( 0 ); */
  171.  
  172.     XfeAllocatePixmapFromData(data,
  173.                               XtDisplay(w),
  174.                               DefaultRootWindow(XtDisplay(w)),
  175.                               XfeColormap(w),
  176.                               40000,
  177.                               XfeDepth(w),
  178.                               XfeBackground(w),
  179.                               &pixmap,
  180.                               &mask);
  181.     
  182.     if (XfePixmapGood(mask))
  183.     {
  184.         XFreePixmap(XtDisplay(w),mask);
  185.     }
  186.     
  187.     return pixmap;
  188. }
  189. /*----------------------------------------------------------------------*/
  190. XfePixmapTable
  191. XfeAllocatePixmapTable(Widget w,String * files,Cardinal num_files)
  192. {
  193.     XfePixmapTable    table = NULL;
  194.     Cardinal        i;
  195.  
  196.     assert( files != NULL );
  197.     assert( num_files > 0 );
  198.  
  199.     table = (XfePixmapTable) XtMalloc(sizeof(Pixmap) * num_files);
  200.  
  201.     assert( table != NULL );
  202.  
  203.     for(i = 0; i < num_files; i++)
  204.     {
  205.         table[i] = XfeGetPixmapFromFile(w,files[i]);
  206.     }
  207.  
  208.     return table;
  209. }
  210. /*----------------------------------------------------------------------*/
  211.