1998-03-28 05:44:41 +03:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
1998-07-29 13:53:53 +04:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------*/
|
1998-03-28 05:44:41 +03:00
|
|
|
/* */
|
|
|
|
/* Name: <XfeTest/TestPixmap.c> */
|
|
|
|
/* Description: Xfe widget pixmap test funcs. */
|
|
|
|
/* Author: Ramiro Estrugo <ramiro@netscape.com> */
|
|
|
|
/* */
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
|
1998-04-08 08:25:42 +04:00
|
|
|
#include <Xfe/XfeTest.h>
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-07-31 15:00:24 +04:00
|
|
|
#ifdef XFE_USE_NATIVE_XPM
|
1998-03-28 05:44:41 +03:00
|
|
|
#include <X11/xpm.h>
|
|
|
|
#endif
|
|
|
|
|
1998-07-31 15:23:36 +04:00
|
|
|
#define DUMB_ASS_DEFAULT "75_foreground"
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
Boolean
|
|
|
|
XfeAllocatePixmapFromFile(char * filename,
|
|
|
|
Display * dpy,
|
|
|
|
Drawable d,
|
|
|
|
Colormap colormap,
|
|
|
|
Cardinal closeness,
|
|
|
|
Cardinal depth,
|
|
|
|
Pixel bg,
|
|
|
|
Pixmap * pixmap,
|
|
|
|
Pixmap * mask)
|
|
|
|
{
|
|
|
|
Boolean result = True;
|
1998-07-31 15:00:24 +04:00
|
|
|
|
|
|
|
#ifdef XFE_USE_NATIVE_XPM
|
|
|
|
XpmAttributes attrib;
|
1998-03-28 05:44:41 +03:00
|
|
|
XpmColorSymbol symbols[1];
|
|
|
|
|
|
|
|
assert( dpy != NULL );
|
|
|
|
assert( d != None );
|
|
|
|
assert( colormap != None );
|
|
|
|
assert( pixmap != NULL );
|
|
|
|
assert( mask != NULL );
|
|
|
|
assert( depth > 0 );
|
|
|
|
assert( filename != NULL );
|
|
|
|
assert( access(filename,F_OK | R_OK) == 0 );
|
|
|
|
|
|
|
|
/* Set up the transparent symbol */
|
|
|
|
symbols[0].name = NULL;
|
|
|
|
symbols[0].value = "none";
|
|
|
|
symbols[0].pixel = bg;
|
|
|
|
|
|
|
|
/* Set up the Xfem Attributes mask and strucutre */
|
|
|
|
attrib.valuemask =
|
|
|
|
XpmCloseness | XpmDepth | XpmColormap | XpmColorSymbols;
|
|
|
|
|
|
|
|
attrib.colorsymbols = symbols;
|
|
|
|
attrib.numsymbols = 1;
|
|
|
|
attrib.closeness = closeness;
|
|
|
|
attrib.colormap = colormap;
|
|
|
|
attrib.depth = depth;
|
|
|
|
|
|
|
|
/* Try to read the xpm file */
|
|
|
|
if (XpmReadFileToPixmap(dpy,d,filename,pixmap,mask,&attrib) != XpmSuccess)
|
|
|
|
{
|
|
|
|
*pixmap = XmUNSPECIFIED_PIXMAP;
|
|
|
|
*mask = XmUNSPECIFIED_PIXMAP;
|
|
|
|
|
|
|
|
result = False;
|
|
|
|
}
|
|
|
|
|
1998-07-31 15:00:24 +04:00
|
|
|
#else
|
|
|
|
|
1998-07-31 15:23:36 +04:00
|
|
|
/* Pick a dumb ass default so that loser platform will at least run */
|
|
|
|
*pixmap = XmGetPixmap(DefaultScreenOfDisplay(dpy),
|
|
|
|
DUMB_ASS_DEFAULT,
|
|
|
|
BlackPixelOfScreen(DefaultScreenOfDisplay(dpy)),
|
|
|
|
bg);
|
|
|
|
|
1998-07-31 15:25:15 +04:00
|
|
|
assert( *pixmap != XmUNSPECIFIED_PIXMAP );
|
1998-07-31 15:23:36 +04:00
|
|
|
|
1998-07-31 15:00:24 +04:00
|
|
|
*mask = XmUNSPECIFIED_PIXMAP;
|
|
|
|
|
1998-07-31 15:23:36 +04:00
|
|
|
result = True;
|
1998-07-31 15:00:24 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
Boolean
|
|
|
|
XfeAllocatePixmapFromData(char ** data,
|
|
|
|
Display * dpy,
|
|
|
|
Drawable d,
|
|
|
|
Colormap colormap,
|
|
|
|
Cardinal closeness,
|
|
|
|
Cardinal depth,
|
|
|
|
Pixel bg,
|
|
|
|
Pixmap * pixmap,
|
|
|
|
Pixmap * mask)
|
|
|
|
{
|
|
|
|
Boolean result = True;
|
1998-07-31 15:00:24 +04:00
|
|
|
|
|
|
|
#ifdef XFE_USE_NATIVE_XPM
|
|
|
|
XpmAttributes attrib;
|
1998-03-28 05:44:41 +03:00
|
|
|
XpmColorSymbol symbols[1];
|
|
|
|
|
|
|
|
assert( dpy != NULL );
|
|
|
|
assert( d != None );
|
|
|
|
assert( colormap != None );
|
|
|
|
assert( pixmap != NULL );
|
|
|
|
assert( mask != NULL );
|
|
|
|
assert( depth > 0 );
|
|
|
|
assert( data != NULL );
|
|
|
|
|
|
|
|
/* Set up the transparent symbol */
|
|
|
|
symbols[0].name = NULL;
|
|
|
|
symbols[0].value = "none";
|
|
|
|
symbols[0].pixel = bg;
|
|
|
|
|
|
|
|
/* Set up the Xfem Attributes mask and strucutre */
|
|
|
|
attrib.valuemask =
|
|
|
|
XpmCloseness | XpmDepth | XpmColormap | XpmColorSymbols;
|
|
|
|
|
|
|
|
attrib.colorsymbols = symbols;
|
|
|
|
attrib.numsymbols = 1;
|
|
|
|
attrib.closeness = closeness;
|
|
|
|
attrib.colormap = colormap;
|
|
|
|
attrib.depth = depth;
|
|
|
|
|
|
|
|
if (XpmCreatePixmapFromData(dpy,d,data,pixmap,mask,&attrib) != XpmSuccess)
|
|
|
|
{
|
|
|
|
*pixmap = XmUNSPECIFIED_PIXMAP;
|
|
|
|
*mask = XmUNSPECIFIED_PIXMAP;
|
|
|
|
|
|
|
|
result = False;
|
|
|
|
}
|
|
|
|
|
1998-07-31 15:00:24 +04:00
|
|
|
#else
|
|
|
|
|
1998-07-31 15:23:36 +04:00
|
|
|
/* Pick a dumb ass default so that loser platform will at least run */
|
|
|
|
*pixmap = XmGetPixmap(DefaultScreenOfDisplay(dpy),
|
|
|
|
DUMB_ASS_DEFAULT,
|
|
|
|
BlackPixelOfScreen(DefaultScreenOfDisplay(dpy)),
|
|
|
|
bg);
|
|
|
|
|
1998-07-31 15:25:15 +04:00
|
|
|
assert( *pixmap != XmUNSPECIFIED_PIXMAP );
|
1998-07-31 15:23:36 +04:00
|
|
|
|
1998-07-31 15:00:24 +04:00
|
|
|
*mask = XmUNSPECIFIED_PIXMAP;
|
|
|
|
|
1998-07-31 15:23:36 +04:00
|
|
|
result = True;
|
1998-07-31 15:00:24 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
Pixmap
|
|
|
|
XfeGetPixmapFromFile(Widget w,char * filename)
|
|
|
|
{
|
|
|
|
Pixmap pixmap = XmUNSPECIFIED_PIXMAP;
|
1998-07-31 15:23:36 +04:00
|
|
|
Pixmap mask = XmUNSPECIFIED_PIXMAP;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
assert( filename != NULL );
|
|
|
|
|
1998-07-31 15:23:36 +04:00
|
|
|
#ifdef XFE_USE_NATIVE_XPM
|
1998-03-28 05:44:41 +03:00
|
|
|
XfeAllocatePixmapFromFile(filename,
|
|
|
|
XtDisplay(w),
|
|
|
|
DefaultRootWindow(XtDisplay(w)),
|
|
|
|
XfeColormap(w),
|
|
|
|
40000,
|
|
|
|
XfeDepth(w),
|
|
|
|
XfeBackground(w),
|
|
|
|
&pixmap,
|
|
|
|
&mask);
|
1998-07-31 15:23:36 +04:00
|
|
|
#else
|
|
|
|
|
|
|
|
pixmap = XmGetPixmap(XtScreen(w),
|
|
|
|
DUMB_ASS_DEFAULT,
|
|
|
|
XfeForeground(w),
|
|
|
|
XfeBackground(w));
|
|
|
|
|
|
|
|
assert( pixmap != XmUNSPECIFIED_PIXMAP );
|
|
|
|
|
|
|
|
#endif
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
if (XfePixmapGood(mask))
|
|
|
|
{
|
|
|
|
XFreePixmap(XtDisplay(w),mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
Pixmap
|
|
|
|
XfeGetPixmapFromData(Widget w,char ** data)
|
|
|
|
{
|
|
|
|
Pixmap pixmap = XmUNSPECIFIED_PIXMAP;
|
1998-07-31 15:23:36 +04:00
|
|
|
Pixmap mask = XmUNSPECIFIED_PIXMAP;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
assert( data != NULL );
|
|
|
|
|
1998-07-31 15:23:36 +04:00
|
|
|
#ifdef XFE_USE_NATIVE_XPM
|
1998-03-28 05:44:41 +03:00
|
|
|
XfeAllocatePixmapFromData(data,
|
|
|
|
XtDisplay(w),
|
|
|
|
DefaultRootWindow(XtDisplay(w)),
|
|
|
|
XfeColormap(w),
|
|
|
|
40000,
|
|
|
|
XfeDepth(w),
|
|
|
|
XfeBackground(w),
|
|
|
|
&pixmap,
|
|
|
|
&mask);
|
1998-07-31 15:23:36 +04:00
|
|
|
#else
|
|
|
|
|
|
|
|
pixmap = XmGetPixmap(XtScreen(w),
|
|
|
|
DUMB_ASS_DEFAULT,
|
|
|
|
XfeForeground(w),
|
|
|
|
XfeBackground(w));
|
|
|
|
|
|
|
|
assert( pixmap != XmUNSPECIFIED_PIXMAP );
|
|
|
|
|
|
|
|
#endif
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
if (XfePixmapGood(mask))
|
|
|
|
{
|
|
|
|
XFreePixmap(XtDisplay(w),mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
XfePixmapTable
|
|
|
|
XfeAllocatePixmapTable(Widget w,String * files,Cardinal num_files)
|
|
|
|
{
|
|
|
|
XfePixmapTable table = NULL;
|
|
|
|
Cardinal i;
|
|
|
|
|
|
|
|
assert( files != NULL );
|
|
|
|
assert( num_files > 0 );
|
|
|
|
|
|
|
|
table = (XfePixmapTable) XtMalloc(sizeof(Pixmap) * num_files);
|
|
|
|
|
|
|
|
assert( table != NULL );
|
|
|
|
|
|
|
|
for(i = 0; i < num_files; i++)
|
|
|
|
{
|
|
|
|
table[i] = XfeGetPixmapFromFile(w,files[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
/*----------------------------------------------------------------------*/
|