Init
This commit is contained in:
23
usr.lib/libsuntool/icon/Makefile
Normal file
23
usr.lib/libsuntool/icon/Makefile
Normal file
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# @(#)Makefile 1.1 94/10/31 SMI
|
||||
#
|
||||
WHOAMI= icon
|
||||
#HDRSPUBLIC= icon.h icon_load.h
|
||||
HDRSPRIVATE=
|
||||
CFILESLIB= icon.c icon_object.c icon_load.c
|
||||
OBJS= $(CFILESLIB:%.c=$(VARIANT)/%.o)
|
||||
TAGFILESALL= ${FULLPATH}/icon.c ${FULLPATH}/icon_object.c \
|
||||
${FULLPATH}/icon_load.c ${FULLPATH}/icon.h \
|
||||
${FULLPATH}/icon_load.h
|
||||
all: xall
|
||||
|
||||
include ../Makefile.arch
|
||||
include ../Makefile.master
|
||||
|
||||
.KEEP_STATE:
|
||||
|
||||
xall: $$(LIBS)
|
||||
$(LIBS) : $$(VARIANT) $(HDRSPUBLIC) $(HDRSPRIVATE) $$(OBJS)
|
||||
|
||||
clean: master.clean
|
||||
|
||||
83
usr.lib/libsuntool/icon/icon.c
Normal file
83
usr.lib/libsuntool/icon/icon.c
Normal file
@@ -0,0 +1,83 @@
|
||||
#ifndef lint
|
||||
#ifdef sccs
|
||||
static char sccsid[] = "@(#)icon.c 1.1 94/10/31 Copyr 1984 Sun Micro";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright (c) 1984 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* icon.c - Display icon.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <pixrect/pixrect_hs.h>
|
||||
#include <sunwindow/rect.h>
|
||||
#include <sunwindow/rectlist.h>
|
||||
#include <sunwindow/pixwin.h>
|
||||
#include <suntool/icon.h>
|
||||
|
||||
void
|
||||
icon_display(icon, pixwin, x, y)
|
||||
register struct icon *icon;
|
||||
register struct pixwin *pixwin;
|
||||
register int x, y;
|
||||
{
|
||||
struct rect textrect;
|
||||
extern struct pixrect *tool_bkgrd;
|
||||
|
||||
#ifdef i386
|
||||
pr_flip(icon->ic_mpr);
|
||||
pr_flip(icon->ic_background);
|
||||
#endif
|
||||
if (icon->ic_flags & ICON_BKGRDGRY || icon->ic_flags & ICON_BKGRDPAT) {
|
||||
/*
|
||||
* Cover the icon's rect with pattern
|
||||
*/
|
||||
(void)pw_replrop(pixwin, x, y,
|
||||
icon->ic_width, icon->ic_height, PIX_SRC,
|
||||
(icon->ic_flags & ICON_BKGRDGRY)? tool_bkgrd:
|
||||
icon->ic_background, 0, 0);
|
||||
} else if (icon->ic_flags & ICON_BKGRDCLR ||
|
||||
icon->ic_flags & ICON_BKGRDSET) {
|
||||
/*
|
||||
* Cover the icon's rect with solid.
|
||||
*/
|
||||
(void)pw_writebackground(pixwin, x, y,
|
||||
icon->ic_width, icon->ic_height,
|
||||
(icon->ic_flags & ICON_BKGRDCLR)? PIX_CLR: PIX_SET);
|
||||
}
|
||||
if (icon->ic_mpr)
|
||||
/*
|
||||
* Copy image over gray
|
||||
*/
|
||||
(void)pw_write(pixwin,
|
||||
icon->ic_gfxrect.r_left+x, icon->ic_gfxrect.r_top+y,
|
||||
icon->ic_gfxrect.r_width, icon->ic_gfxrect.r_height,
|
||||
PIX_SRC, icon->ic_mpr, 0, 0);
|
||||
if (icon->ic_text && (icon->ic_text[0] != '\0')) {
|
||||
extern PIXFONT *pw_pfsysopen();
|
||||
|
||||
if (!icon->ic_font)
|
||||
icon->ic_font = pw_pfsysopen();
|
||||
if (rect_isnull(&icon->ic_textrect))
|
||||
/* Set text rect to accomodate 1 line at bottom. */
|
||||
rect_construct(&icon->ic_textrect,
|
||||
0, icon->ic_height-icon->ic_font->pf_defaultsize.y,
|
||||
icon->ic_width, icon->ic_font->pf_defaultsize.y);
|
||||
/* Blank out area onto which text will go. */
|
||||
(void)pw_writebackground(pixwin,
|
||||
icon->ic_textrect.r_left+x, icon->ic_textrect.r_top+y,
|
||||
icon->ic_textrect.r_width, icon->ic_textrect.r_height,
|
||||
PIX_CLR);
|
||||
/* Format text into textrect */
|
||||
textrect = icon->ic_textrect;
|
||||
textrect.r_left += x;
|
||||
textrect.r_top += y;
|
||||
(void)formatstringtorect(pixwin, icon->ic_text, icon->ic_font,
|
||||
&textrect);
|
||||
}
|
||||
}
|
||||
|
||||
296
usr.lib/libsuntool/icon/icon_load.c
Normal file
296
usr.lib/libsuntool/icon/icon_load.c
Normal file
@@ -0,0 +1,296 @@
|
||||
#ifndef lint
|
||||
#ifdef sccs
|
||||
static char sccsid[] = "@(#)icon_load.c 1.1 94/10/31 SMI";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright 1984-1989 Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <pixrect/pixrect.h>
|
||||
#include <pixrect/pixfont.h>
|
||||
#include <pixrect/memvar.h>
|
||||
#include <sunwindow/rect.h>
|
||||
#include <suntool/icon.h>
|
||||
#include <suntool/icon_load.h>
|
||||
|
||||
#define NULL_PIXRECT ((struct pixrect *)0)
|
||||
#define NULL_PIXFONT ((struct pixfont *)0)
|
||||
extern char *sprintf();
|
||||
extern char *malloc();
|
||||
|
||||
FILE *
|
||||
icon_open_header(from_file, error_msg, info)
|
||||
char *from_file, *error_msg;
|
||||
register icon_header_handle info;
|
||||
/* See comments in icon_load.h */
|
||||
{
|
||||
#define INVALID -1
|
||||
register int c;
|
||||
char c_temp;
|
||||
register FILE *result;
|
||||
|
||||
if (from_file == "" ||
|
||||
(result = fopen(from_file, "r")) == NULL) {
|
||||
(void)sprintf(error_msg, "Cannot open file %s.\n", from_file);
|
||||
goto ErrorReturn;
|
||||
}
|
||||
info->depth = INVALID;
|
||||
info->height = INVALID;
|
||||
info->format_version = INVALID;
|
||||
info->valid_bits_per_item = INVALID;
|
||||
info->width = INVALID;
|
||||
info->last_param_pos = INVALID;
|
||||
/*
|
||||
* Parse the file header
|
||||
*/
|
||||
do {
|
||||
if ((c = fscanf(result, "%*[^DFHVW*]")) == EOF)
|
||||
break;
|
||||
switch (c = getc(result)) {
|
||||
case 'D': if (info->depth == INVALID) {
|
||||
c = fscanf(result, "epth=%d", &info->depth);
|
||||
if (c == 0) c = 1;
|
||||
else info->last_param_pos = ftell(result);
|
||||
}
|
||||
break;
|
||||
case 'H': if (info->height == INVALID) {
|
||||
c = fscanf(result, "eight=%d", &info->height);
|
||||
if (c == 0) c = 1;
|
||||
else info->last_param_pos = ftell(result);
|
||||
}
|
||||
break;
|
||||
case 'F': if (info->format_version == INVALID) {
|
||||
c = fscanf(result, "ormat_version=%d",
|
||||
&info->format_version);
|
||||
if (c == 0) c = 1;
|
||||
else info->last_param_pos = ftell(result);
|
||||
}
|
||||
break;
|
||||
case 'V': if (info->valid_bits_per_item == INVALID) {
|
||||
c = fscanf(result, "alid_bits_per_item=%d",
|
||||
&info->valid_bits_per_item);
|
||||
if (c == 0) c = 1;
|
||||
else info->last_param_pos = ftell(result);
|
||||
}
|
||||
break;
|
||||
case 'W': if (info->width == INVALID) {
|
||||
c = fscanf(result, "idth=%d", &info->width);
|
||||
if (c == 0) c = 1;
|
||||
else info->last_param_pos = ftell(result);
|
||||
}
|
||||
break;
|
||||
case '*': if (info->format_version == 1) {
|
||||
c = fscanf(result, "%c", &c_temp);
|
||||
if (c_temp == '/') c = 0; /* Force exit */
|
||||
else (void)ungetc(c_temp, result);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
c = EOF; /* force error */
|
||||
break;
|
||||
}
|
||||
} while (c != 0 && c != EOF);
|
||||
if (c == EOF || info->format_version != 1) {
|
||||
(void)sprintf(error_msg, "%s has invalid header format.\n", from_file);
|
||||
goto ErrorReturn;
|
||||
}
|
||||
if (info->depth == INVALID)
|
||||
info->depth = 1;
|
||||
if (info->height == INVALID)
|
||||
info->height = 64;
|
||||
if (info->valid_bits_per_item == INVALID)
|
||||
info->valid_bits_per_item = 16;
|
||||
if (info->width == INVALID)
|
||||
info->width = 64;
|
||||
if (info->depth != 1) {
|
||||
(void)sprintf(error_msg, "Cannot handle Depth of %d.\n", info->depth);
|
||||
goto ErrorReturn;
|
||||
}
|
||||
if (info->valid_bits_per_item != 16 &&
|
||||
info->valid_bits_per_item != 32) {
|
||||
(void)sprintf(error_msg, "Cannot handle Valid_bits_per_item of %d.\n",
|
||||
info->valid_bits_per_item);
|
||||
goto ErrorReturn;
|
||||
}
|
||||
return(result);
|
||||
|
||||
ErrorReturn:
|
||||
if (result)
|
||||
(void)fclose(result);
|
||||
return(NULL);
|
||||
#undef INVALID
|
||||
}
|
||||
|
||||
int
|
||||
icon_read_pr(fd, header, pr)
|
||||
FILE *fd;
|
||||
register icon_header_handle header;
|
||||
struct pixrect *pr;
|
||||
{
|
||||
register struct mpr_data *mprd;
|
||||
int linebytes, linepad;
|
||||
register int count;
|
||||
short *image;
|
||||
|
||||
mprd = (struct mpr_data *)(LINT_CAST(pr->pr_data));
|
||||
|
||||
if ((header->valid_bits_per_item != 16 &&
|
||||
header->valid_bits_per_item != 32) ||
|
||||
MP_NOTMPR(pr) ||
|
||||
mprd->md_flags & MP_REVERSEVIDEO ||
|
||||
mprd->md_offset.x != 0 ||
|
||||
mprd->md_offset.y != 0)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* Icon data in files follows the static pixrect (16 bit) padding
|
||||
* rule while memory pixrect may have 32 bit padding.
|
||||
*/
|
||||
linebytes = mpr_linebytes(header->width, header->depth);
|
||||
linepad = mprd->md_linebytes - linebytes;
|
||||
|
||||
count = linebytes * header->height;
|
||||
|
||||
/*
|
||||
* If memory pixrect is padded more than icon data, allocate
|
||||
* a scratch buffer for the data; otherwise read it directly
|
||||
* into the pixrect image.
|
||||
*/
|
||||
if (linepad) {
|
||||
image = (short *) malloc((unsigned) count);
|
||||
if (image == 0)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
image = mprd->md_image;
|
||||
|
||||
/*
|
||||
* Read the icon image into the pixrect or scratch buffer.
|
||||
*/
|
||||
{
|
||||
register short *p = image;
|
||||
|
||||
while (count > 0) {
|
||||
register int c;
|
||||
long value;
|
||||
|
||||
c = fscanf(fd, " 0x%lx,", &value);
|
||||
if (c == 0 || c == EOF)
|
||||
break;
|
||||
|
||||
if (header->valid_bits_per_item > 16) {
|
||||
#ifdef i386
|
||||
bitflip32(&value);
|
||||
#endif
|
||||
* (long *) p = value;
|
||||
p += 2;
|
||||
count -= 4;
|
||||
}
|
||||
else {
|
||||
#ifdef i386
|
||||
bitflip16(&value);
|
||||
#endif
|
||||
*p++ = value;
|
||||
count -= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy image from scratch buffer to pixrect.
|
||||
*/
|
||||
if (linepad) {
|
||||
register char *in = (char *) image;
|
||||
register char *out = (char *) mprd->md_image;
|
||||
register int h = header->height;
|
||||
|
||||
while (--h >= 0) {
|
||||
bcopy(in, out, linebytes);
|
||||
in += linebytes;
|
||||
out += linebytes + linepad;
|
||||
}
|
||||
|
||||
(void) free((char *) image);
|
||||
}
|
||||
|
||||
return count > 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
struct pixrect *
|
||||
icon_load_mpr(from_file, error_msg)
|
||||
char *from_file, *error_msg;
|
||||
/* See comments in icon_load.h */
|
||||
{
|
||||
register FILE *fd;
|
||||
icon_header_object header;
|
||||
register struct pixrect *result;
|
||||
|
||||
fd = icon_open_header(from_file, error_msg, &header);
|
||||
if (fd == NULL)
|
||||
return(NULL_PIXRECT);
|
||||
/*
|
||||
* Allocate the pixrect and read the actual bits making up the icon.
|
||||
*/
|
||||
result = mem_create(header.width, header.height, header.depth);
|
||||
if (result == NULL_PIXRECT) {
|
||||
(void)sprintf(error_msg, "Cannot create memory pixrect %dx%dx%d.\n",
|
||||
header.width, header.height, header.depth);
|
||||
}
|
||||
else if (icon_read_pr(fd, &header, result) != 0) {
|
||||
(void) pr_destroy(result);
|
||||
result = NULL_PIXRECT;
|
||||
(void) sprintf(error_msg,
|
||||
"Error reading icon data.\n");
|
||||
}
|
||||
(void)fclose(fd);
|
||||
return(result);
|
||||
}
|
||||
|
||||
int
|
||||
icon_init_from_pr(icon, pr)
|
||||
register struct icon *icon;
|
||||
register struct pixrect *pr;
|
||||
/* See comments in icon_load.h */
|
||||
{
|
||||
icon->ic_mpr = pr;
|
||||
/*
|
||||
* Set the icon's size and graphics area to match its pixrect's extent.
|
||||
*/
|
||||
icon->ic_gfxrect.r_top = icon->ic_gfxrect.r_left = 0;
|
||||
icon->ic_gfxrect.r_width = icon->ic_width = pr->pr_size.x;
|
||||
icon->ic_gfxrect.r_height = icon->ic_height = pr->pr_size.y;
|
||||
/*
|
||||
* By default, the icon has no text or associated area and font.
|
||||
*/
|
||||
icon->ic_textrect = rect_null;
|
||||
icon->ic_text = NULL;
|
||||
icon->ic_font = NULL_PIXFONT;
|
||||
/*
|
||||
* Also, by default, the icon has no background pattern.
|
||||
*/
|
||||
icon->ic_background = NULL_PIXRECT;
|
||||
icon->ic_flags = 0;
|
||||
}
|
||||
|
||||
int
|
||||
icon_load(icon, from_file, error_msg)
|
||||
register struct icon *icon;
|
||||
char *from_file, *error_msg;
|
||||
/* See comments in icon_load.h */
|
||||
{
|
||||
register struct pixrect *pr;
|
||||
|
||||
pr = icon_load_mpr(from_file, error_msg);
|
||||
if (pr == NULL_PIXRECT)
|
||||
return(1);
|
||||
(void)icon_init_from_pr(icon, pr);
|
||||
#ifdef i386
|
||||
pr_flip(pr);
|
||||
#endif
|
||||
return(0);
|
||||
}
|
||||
|
||||
198
usr.lib/libsuntool/icon/icon_object.c
Normal file
198
usr.lib/libsuntool/icon/icon_object.c
Normal file
@@ -0,0 +1,198 @@
|
||||
#ifndef lint
|
||||
#ifdef sccs
|
||||
static char sccsid[] = "@(#)icon_object.c 1.1 94/10/31 Copyr 1984 Sun Micro";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
/* icon_object.c */
|
||||
/* Copyright (c) 1985 by Sun Microsystems, Inc. */
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <varargs.h>
|
||||
#include <pixrect/pixrect_hs.h>
|
||||
#include <sunwindow/rect.h>
|
||||
#include <sunwindow/rectlist.h>
|
||||
#include <sunwindow/pixwin.h>
|
||||
#include <suntool/icon.h>
|
||||
|
||||
static int icon_init_attrs(), icon_set_attrs();
|
||||
|
||||
/*****************************************************************************/
|
||||
/* icon_create */
|
||||
/*****************************************************************************/
|
||||
|
||||
/* VARARGS0 */
|
||||
Icon
|
||||
icon_create(va_alist)
|
||||
va_dcl
|
||||
{
|
||||
Attr_avlist avlist[ATTR_STANDARD_SIZE];
|
||||
va_list valist;
|
||||
register struct icon *icon;
|
||||
char *calloc();
|
||||
extern PIXFONT *pw_pfsysopen();
|
||||
|
||||
va_start(valist);
|
||||
(void)attr_make((char **)avlist, ATTR_STANDARD_SIZE, valist);
|
||||
va_end(valist);
|
||||
|
||||
if (!(icon = (struct icon *) (LINT_CAST(calloc (1, sizeof(struct icon))))))
|
||||
return NULL;
|
||||
|
||||
icon_init_attrs(icon);
|
||||
|
||||
(void)icon_set_attrs(icon, avlist);
|
||||
|
||||
if (!icon->ic_font)
|
||||
icon->ic_font = pw_pfsysopen();
|
||||
|
||||
return (Icon) icon;
|
||||
}
|
||||
|
||||
static
|
||||
icon_init_attrs(icon)
|
||||
register icon_handle icon;
|
||||
{
|
||||
icon->ic_width = 64;
|
||||
icon->ic_height = 64;
|
||||
icon->ic_gfxrect.r_width = 64;
|
||||
icon->ic_gfxrect.r_height = 64;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* icon_destroy */
|
||||
/*****************************************************************************/
|
||||
|
||||
icon_destroy(icon_client)
|
||||
Icon icon_client;
|
||||
{
|
||||
icon_handle icon;
|
||||
|
||||
icon = (icon_handle)(LINT_CAST(icon_client));
|
||||
free((char *)(LINT_CAST(icon)));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* icon_set */
|
||||
/*****************************************************************************/
|
||||
|
||||
/*VARARGS1*/
|
||||
int
|
||||
icon_set(icon_client, va_alist)
|
||||
Icon icon_client;
|
||||
va_dcl
|
||||
{
|
||||
Attr_avlist avlist[ATTR_STANDARD_SIZE];
|
||||
va_list valist;
|
||||
icon_handle icon;
|
||||
|
||||
icon = (icon_handle)(LINT_CAST(icon_client));
|
||||
va_start(valist);
|
||||
(void)attr_make((char **)avlist, ATTR_STANDARD_SIZE, valist);
|
||||
va_end(valist);
|
||||
return icon_set_attrs(icon, avlist);
|
||||
}
|
||||
|
||||
/*VARARGS1*/
|
||||
static int
|
||||
icon_set_attrs(icon, avlist)
|
||||
register icon_handle icon;
|
||||
register Attr_avlist avlist;
|
||||
{
|
||||
register Icon_attribute attr;
|
||||
Rect *r;
|
||||
|
||||
while (attr = (Icon_attribute) *avlist++) {
|
||||
switch (attr) {
|
||||
|
||||
case ICON_X:
|
||||
avlist++;
|
||||
break;
|
||||
|
||||
case ICON_Y:
|
||||
avlist++;
|
||||
break;
|
||||
|
||||
case ICON_WIDTH:
|
||||
icon->ic_width = (short) *avlist++;
|
||||
break;
|
||||
|
||||
case ICON_HEIGHT:
|
||||
icon->ic_height = (short) (LINT_CAST(*avlist++));
|
||||
break;
|
||||
|
||||
case ICON_IMAGE:
|
||||
icon->ic_mpr = (struct pixrect *) (LINT_CAST(*avlist++));
|
||||
break;
|
||||
|
||||
case ICON_IMAGE_RECT:
|
||||
r = (Rect *) (LINT_CAST(*avlist++));
|
||||
if (r)
|
||||
icon->ic_gfxrect = *r;
|
||||
break;
|
||||
|
||||
case ICON_LABEL_RECT:
|
||||
r = (Rect *) (LINT_CAST(*avlist++));
|
||||
if (r)
|
||||
icon->ic_textrect = *r;
|
||||
break;
|
||||
|
||||
case ICON_LABEL:
|
||||
icon->ic_text = (char *) *avlist++;
|
||||
break;
|
||||
|
||||
case ICON_FONT:
|
||||
icon->ic_font = (struct pixfont *) (LINT_CAST(*avlist++));
|
||||
break;
|
||||
|
||||
default:
|
||||
avlist = attr_skip(attr, avlist);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* icon_get */
|
||||
/*****************************************************************************/
|
||||
|
||||
caddr_t
|
||||
icon_get(icon_client, attr)
|
||||
register Icon icon_client;
|
||||
Icon_attribute attr;
|
||||
{
|
||||
icon_handle icon;
|
||||
|
||||
icon = (icon_handle)(LINT_CAST(icon_client));
|
||||
switch (attr) {
|
||||
|
||||
case ICON_WIDTH:
|
||||
return (caddr_t) icon->ic_width;
|
||||
|
||||
case ICON_HEIGHT:
|
||||
return (caddr_t) icon->ic_height;
|
||||
|
||||
case ICON_IMAGE:
|
||||
return (caddr_t) icon->ic_mpr;
|
||||
|
||||
case ICON_IMAGE_RECT:
|
||||
return (caddr_t) &(icon->ic_gfxrect);
|
||||
|
||||
case ICON_LABEL_RECT:
|
||||
return (caddr_t) &(icon->ic_textrect);
|
||||
|
||||
case ICON_LABEL:
|
||||
return (caddr_t) icon->ic_text;
|
||||
|
||||
case ICON_FONT:
|
||||
return (caddr_t) icon->ic_font;
|
||||
|
||||
case ICON_X:
|
||||
case ICON_Y:
|
||||
default:
|
||||
return (caddr_t) NULL;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user