[comp.sources.x] v02i074: postit notes, Part01/02

mikew@wyse.wyse.com (Mike Wexler) (01/05/89)

Submitted-by: davy@riacs.edu (Dave Curry)
Posting-number: Volume 2, Issue 74
Archive-name: postit/part01

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 2)."
# Contents:  README Imakefile Makefile Plaid.c confirm.c menu.c note.c
#   plaid.c xpostit.c xpostit.h xpostit.man
# Wrapped by mikew@wyse on Wed Jan  4 10:09:51 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(450 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XWell, I finally got around to rewriting my xpostit program for X11.
XXpostit allows you to place small "Post-it note" windows all over
Xyour screen, as opposed to sticking real Post-it notes all over your
Xworkstation.
X
XThis version is for X11 Release 3 and uses the Athena widgets.  It
Xwill not run under X11 Release 2, since it uses the List widget,
Xwhich didn't exist then.
X
XDave Curry
XResearch Institute for Advanced Computer Science
Xdavy@riacs.edu
END_OF_FILE
if test 450 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'Imakefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Imakefile'\"
else
echo shar: Extracting \"'Imakefile'\" \(239 characters\)
sed "s/^X//" >'Imakefile' <<'END_OF_FILE'
XLOCAL_LIBRARIES = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
X           SRCS = Plaid.c confirm.c menu.c note.c plaid.c util.c xpostit.c
X           OBJS = Plaid.o confirm.o menu.o note.o plaid.o util.o xpostit.o
X
XComplexProgramTarget(xpostit)
END_OF_FILE
if test 239 -ne `wc -c <'Imakefile'`; then
    echo shar: \"'Imakefile'\" unpacked with wrong size!
fi
# end of 'Imakefile'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(6545 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# Makefile generated by imake - do not edit!
X# $XConsortium: imake.c,v 1.37 88/10/08 20:08:30 jim Exp $
X#
X# The cpp used on this machine replaces all newlines and multiple tabs and
X# spaces in a macro expansion with a single space.  Imake tries to compensate
X# for this, but is not always successful.
X#
X
X###########################################################################
X# X Window System Makefile generated from template file Imake.tmpl
X# $XConsortium: Imake.tmpl,v 1.91 88/10/23 22:37:10 jim Exp $
X#
X# Do not change the body of the imake template file.  Server-specific
X# parameters may be set in the appropriate .macros file; site-specific
X# parameters (but shared by all servers) may be set in site.def.  If you
X# make any changes, you'll need to rebuild the makefiles using
X# "make World" (at best) or "make Makefile; make Makefiles" (at least) in
X# the top level directory.
X#
X# If your C preprocessor doesn't define any unique symbols, you'll need
X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
X# "make Makefile", "make Makefiles", or "make World").
X#
X# If you absolutely can't get imake to work, you'll need to set the
X# variables at the top of each Makefile as well as the dependencies at the
X# bottom (makedepend will do this automatically).
X#
X
X###########################################################################
X# platform-specific configuration parameters - edit Sun.macros to change
X
X# platform:  $XConsortium: Sun.macros,v 1.52 88/10/23 11:00:55 jim Exp $
X# operating system:   SunOS 3.4
X
XBOOTSTRAPCFLAGS =
X             AS = as
X             CC = cc
X            CPP = /lib/cpp
X             LD = ld
X           LINT = lint
X        INSTALL = install
X           TAGS = ctags
X             RM = rm -f
X             MV = mv
X             LN = ln -s
X         RANLIB = ranlib
XRANLIBINSTFLAGS = -t
X             AR = ar clq
X             LS = ls
X       LINTOPTS = -axz
X    LINTLIBFLAG = -C
X           MAKE = make
XSTD_CPP_DEFINES =
X    STD_DEFINES =
X
X###########################################################################
X# site-specific configuration parameters - edit site.def to change
X
X# site:  $XConsortium: site.def,v 1.16 88/10/12 10:30:24 jim Exp $
X
X###########################################################################
X# definitions common to all Makefiles - do not edit
X
X          SHELL =  /bin/sh
X
X        DESTDIR = /global
X      USRLIBDIR = $(DESTDIR)/lib
X         BINDIR = $(DESTDIR)/bin/X11
X         INCDIR = $(DESTDIR)/include
X         ADMDIR = $(DESTDIR)/usr/adm
X         LIBDIR = $(USRLIBDIR)/X11
X     LINTLIBDIR = $(USRLIBDIR)/lint
X        FONTDIR = $(LIBDIR)/fonts
X       XINITDIR = $(LIBDIR)/xinit
X         XDMDIR = $(LIBDIR)/xdm
X         UWMDIR = $(LIBDIR)/uwm
X         AWMDIR = $(LIBDIR)/awm
X         TWMDIR = $(LIBDIR)/twm
X          DTDIR = $(LIBDIR)/dt
X        MANPATH = /usr/man
X  MANSOURCEPATH = $(MANPATH)/man
X         MANDIR = $(MANSOURCEPATH)n
X      LIBMANDIR = $(MANSOURCEPATH)n3
X    XAPPLOADDIR = $(LIBDIR)/app-defaults
X
X   INSTBINFLAGS = -m 0755
X   INSTUIDFLAGS = -m 4755
X   INSTLIBFLAGS = -m 0664
X   INSTINCFLAGS = -m 0444
X   INSTMANFLAGS = -m 0444
X   INSTAPPFLAGS = -m 0444
X  INSTKMEMFLAGS = -m 4755
X        FCFLAGS = -t
X    CDEBUGFLAGS = -O
X
X        PATHSEP = /
X         DEPEND = $(BINDIR)/makedepend
X          IMAKE = $(BINDIR)/imake
X            RGB = $(LIBDIR)/rgb
X             FC = $(BINDIR)/bdftosnf
X      MKFONTDIR = $(BINDIR)/mkfontdir
X      MKDIRHIER = $(BINDIR)/mkdirhier.sh
X
X         CFLAGS = $(CDEBUGFLAGS) $(INCLUDES) $(STD_DEFINES) $(DEFINES)
X      LINTFLAGS = $(LINTOPTS) $(INCLUDES) $(STD_DEFINES) $(DEFINES) -DLINT
X        LDFLAGS = $(CDEBUGFLAGS) -L$(USRLIBDIR) $(SYS_LIBRARIES) $(SYSAUX_LIBRARIES)
X
X       IRULESRC = $(LIBDIR)/imake.includes
X
X   EXTENSIONLIB = $(USRLIBDIR)/libext.a
X           XLIB = $(USRLIBDIR)/libX11.a
X         XMULIB = $(USRLIBDIR)/libXmu.a
X        OLDXLIB = $(USRLIBDIR)/liboldX.a
X       XTOOLLIB = $(USRLIBDIR)/libXt.a
X         XAWLIB = $(USRLIBDIR)/libXaw.a
X       LINTXLIB = $(USRLIBDIR)/llib-lX11.ln
X        LINTXMU = $(USRLIBDIR)/llib-lXmu.ln
X      LINTXTOOL = $(USRLIBDIR)/llib-lXt.ln
X        LINTXAW = $(USRLIBDIR)/llib-lXaw.ln
X       INCLUDES = -I$(INCDIR)
X      MACROFILE = Sun.macros
X   ICONFIGFILES = $(IRULESRC)/Imake.tmpl \
X			$(IRULESRC)/$(MACROFILE) $(IRULESRC)/site.def
X  IMAKE_DEFINES =
X      IMAKE_CMD = $(NEWTOP)$(IMAKE) -TImake.tmpl -I$(NEWTOP)$(IRULESRC) \
X			-s Makefile $(IMAKE_DEFINES)
X         RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a \
X			.emacs_* tags TAGS make.log MakeOut
X
X###########################################################################
X# rules:  $XConsortium: Imake.rules,v 1.71 88/10/23 22:46:34 jim Exp $
X
X###########################################################################
X# start of Imakefile
X
XLOCAL_LIBRARIES = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
X           SRCS = Plaid.c confirm.c menu.c note.c plaid.c util.c xpostit.c
X           OBJS = Plaid.o confirm.o menu.o note.o plaid.o util.o xpostit.o
X
X PROGRAM = xpostit
X
Xall:: xpostit
X
Xxpostit: $(OBJS) $(LOCAL_LIBRARIES)
X	$(RM) $@
X	$(CC) -o $@ $(OBJS) $(LOCAL_LIBRARIES) $(LDFLAGS) $(SYSLAST_LIBRARIES)
X
Xrelink::
X	$(RM) $(PROGRAM)
X	$(MAKE) $(MFLAGS) $(PROGRAM)
X
Xinstall:: xpostit
X	$(INSTALL) -c $(INSTALLFLAGS) xpostit $(BINDIR)
X
Xinstall.man:: xpostit.man
X	$(INSTALL) -c $(INSTMANFLAGS) xpostit.man $(MANDIR)/xpostit.n
X
Xdepend:: $(DEPEND)
X
Xdepend::
X	$(DEPEND) -s "# DO NOT DELETE" -- $(CFLAGS) -- $(SRCS)
X
X$(DEPEND):
X	@echo "making $@"; \
X	cd $(DEPENDSRC); $(MAKE)
X
Xclean::
X	$(RM) $(PROGRAM)
X
X###########################################################################
X# Imake.tmpl common rules for all Makefiles - do not edit
X
Xemptyrule::
X
Xclean::
X	$(RM_CMD) \#*
X
XMakefile:: $(IMAKE)
X
XMakefile:: Imakefile \
X	$(IRULESRC)/Imake.tmpl \
X	$(IRULESRC)/Imake.rules \
X	$(IRULESRC)/site.def \
X	$(IRULESRC)/$(MACROFILE)
X	-@if [ -f Makefile ]; then \
X	echo "$(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
X	$(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
X	else exit 0; fi
X	$(IMAKE_CMD) -DTOPDIR=$(TOP)
X
X$(IMAKE):
X	@echo "making $@"; \
X	cd $(IMAKESRC); $(MAKE) BOOTSTRAPCFLAGS=$(BOOTSTRAPCFLAGS)
X
Xtags::
X	$(TAGS) -w *.[ch]
X	$(TAGS) -xw *.[ch] > TAGS
X
X###########################################################################
X# empty rules for directories that do not have SUBDIRS - do not edit
X
Xinstall::
X	@echo "install done"
X
Xinstall.man::
X	@echo "install.man done"
X
XMakefiles::
X
X###########################################################################
X# dependencies generated by makedepend
X
END_OF_FILE
if test 6545 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'Plaid.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Plaid.c'\"
else
echo shar: Extracting \"'Plaid.c'\" \(4513 characters\)
sed "s/^X//" >'Plaid.c' <<'END_OF_FILE'
X#ifndef lint
Xstatic char	*RCSid = "$Header$";
X#endif
X
X/*
X * Plaid.c - code for the plaid widget.
X *
X * Based on the Template widget from the X11R3 distribution.
X *
X * David A. Curry
X * Research Institute for Advanced Computer Science
X * Mail Stop 230-5
X * NASA Ames Research Center
X * Moffett Field, CA 94086
X * davy@riacs.edu
X *
X * $Log$
X */
X#include <X11/copyright.h>
X
X#include <X11/IntrinsicP.h>
X#include <X11/StringDefs.h>
X#include "PlaidP.h"
X
X#define plaid_width	22
X#define plaid_height	22
X
X/*
X * The bits representing the plaid background.
X */
Xstatic char plaid_bits[] = {
X   0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e,
X   0x75, 0xfd, 0x3f, 0xff, 0x57, 0x15, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e,
X   0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0x20, 0xa8, 0x2b,
X   0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b,
X   0xff, 0xff, 0x3f, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b,
X   0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b
X};
X
X/*
X * The resources specific to the plaid widget.
X */
Xstatic XtResource resources[] = {
X#define offset(field)	XtOffset(PlaidWidget,plaid.field)
X    { XtNcallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
X	offset(input_callback), XtRCallback, NULL },
X    { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
X        offset(foreground), XtRString, "XtDefaultForeground" }
X#undef offset
X};
X
X/*
X * ButtonAction - called when a button is pressed.
X */
Xstatic void
XButtonAction(w, event, params, num_params)
XCardinal *num_params;	/* unused */
XString *params;		/* unused */
XXEvent *event;
XWidget w;
X{
X	/*
X	 * Just pass it off to the user's callback function.
X	 */
X	XtCallCallbacks(w, XtNcallback, (caddr_t) event);
X}
X
X/*
X * RealizePlaid - realize the window by creating it, and by creating the
X *		  plaid background pixmap.
X */
Xstatic void
XRealizePlaid(w, value_mask, attributes)
XXSetWindowAttributes *attributes;
XMask *value_mask;
XWidget w;
X{
X	Pixmap p;
X	Window window;
X	Display *display;
X	PlaidWidget plaidw;
X
X	plaidw = (PlaidWidget) w;
X
X	/*
X	 * Create the window.
X	 */
X	XtCreateWindow(w, (unsigned int) InputOutput,
X			(Visual *) CopyFromParent, *value_mask, attributes);
X
X	display = XtDisplay(w);
X	window = XtWindow(w);
X
X	/*
X	 * Create the plaid pixmap.
X	 */
X	p = XCreatePixmapFromBitmapData(display, window, plaid_bits,
X			plaid_width, plaid_height, plaidw->plaid.foreground,
X			w->core.background_pixel, w->core.depth);
X
X	/*
X	 * Tile the window.
X	 */
X	XSetWindowBackgroundPixmap(display, window, p);
X
X	/*
X	 * Now save the pixmap in the core widget.
X	 */
X	w->core.background_pixmap = p;
X}
X
X/*
X * DestroyPlaid - free up server resources when widget is destroyed.
X */
Xstatic void
XDestroyPlaid(w)
XWidget w;
X{
X	/*
X	 * All we need to do is get rid of the pixmap we created.
X	 */
X	XFreePixmap(XtDisplay(w), w->core.background_pixmap);
X}
X
X/*
X * Action table.  We're only interested in button presses.
X */
Xstatic XtActionsRec actions[] =
X{
X	{ "button",	ButtonAction }
X};
X
X/*
X * Translation table.  We're only interested in button presses.
X */
Xstatic char translations[] =
X	"<BtnDown>:		button()	\n\
X";
X
X/*
X * The plaid widget class record.   Initialization of values.
X */
XPlaidClassRec plaidClassRec = {
X  { /* core fields */
X    /* superclass		*/	(WidgetClass) &widgetClassRec,
X    /* class_name		*/	"Plaid",
X    /* widget_size		*/	sizeof(PlaidRec),
X    /* class_initialize		*/	NULL,
X    /* class_part_initialize	*/	NULL,
X    /* class_inited		*/	FALSE,
X    /* initialize		*/	NULL,
X    /* initialize_hook		*/	NULL,
X    /* realize			*/	RealizePlaid,
X    /* actions			*/	actions,
X    /* num_actions		*/	XtNumber(actions),
X    /* resources		*/	resources,
X    /* num_resources		*/	XtNumber(resources),
X    /* xrm_class		*/	NULLQUARK,
X    /* compress_motion		*/	TRUE,
X    /* compress_exposure	*/	TRUE,
X    /* compress_enterleave	*/	TRUE,
X    /* visible_interest		*/	FALSE,
X    /* destroy			*/	DestroyPlaid,
X    /* resize			*/	NULL,
X    /* expose			*/	NULL,
X    /* set_values		*/	NULL,
X    /* set_values_hook		*/	NULL,
X    /* set_values_almost	*/	XtInheritSetValuesAlmost,
X    /* get_values_hook		*/	NULL,
X    /* accept_focus		*/	NULL,
X    /* version			*/	XtVersion,
X    /* callback_private		*/	NULL,
X    /* tm_table			*/	translations,
X    /* query_geometry		*/	XtInheritQueryGeometry,
X    /* display_accelerator	*/	XtInheritDisplayAccelerator,
X    /* extension		*/	NULL
X  },
X  { /* plaid fields */
X    /* empty			*/	0
X  }
X};
X
X/*
X * The class declaration.
X */
XWidgetClass plaidWidgetClass = (WidgetClass)&plaidClassRec;
END_OF_FILE
if test 4513 -ne `wc -c <'Plaid.c'`; then
    echo shar: \"'Plaid.c'\" unpacked with wrong size!
fi
# end of 'Plaid.c'
fi
if test -f 'confirm.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'confirm.c'\"
else
echo shar: Extracting \"'confirm.c'\" \(2779 characters\)
sed "s/^X//" >'confirm.c' <<'END_OF_FILE'
X#ifndef lint
Xstatic char	*RCSid = "$Header$";
X#endif
X
X/*
X * confirm.c - handle confirming requests made by the user.
X *
X * David A. Curry
X * Research Institute for Advanced Computer Science
X * Mail Stop 230-5
X * NASA Ames Research Center
X * Moffett Field, CA 94086
X * davy@riacs.edu
X *
X * $Log$
X */
X#include <X11/StringDefs.h>
X#include <X11/Intrinsic.h>
X#include <X11/Command.h>
X#include <X11/Shell.h>
X#include <X11/Form.h>
X#include <stdio.h>
X
X#include "xpostit.h"
X
Xstatic Widget	confirmwidget;
X
X/*
X * ConfirmIt - put up a window asking for confirmation.
X */
Xvoid
XConfirmIt(confirm_callbacks, cancel_callbacks)
XXtCallbackRec *confirm_callbacks, *cancel_callbacks;
X{
X	Arg args[4];
X	Window root, child;
X	register int nargs, nwidgets;
X	static Boolean inited = False;
X	static Widget form, widgets[2];
X	int root_x, root_y, child_x, child_y, buttons;
X
X	/*
X	 * Find out where the mouse is, so we can put the confirmation
X	 * box right there.
X	 */
X	XQueryPointer(display, XtWindow(toplevel), &root, &child,
X			&root_x, &root_y, &child_x, &child_y, &buttons);
X
X	/*
X	 * If we need to construct the confirmation box do that,
X	 * otherwise just reset the position and callbacks and
X	 * put it up again.
X	 */
X	if (!inited) {
X		nargs = 0;
X		SetArg(XtNx, root_x);
X		SetArg(XtNy, root_y);
X
X		/*
X		 * The confirmation box will be a pop-up widget.
X		 */
X		confirmwidget = XtCreatePopupShell("Confirm",
X				overrideShellWidgetClass, toplevel, args,
X				nargs);
X
X		/*
X		 * Make a form to put the buttons in.
X		 */
X		form = XtCreateWidget("form", formWidgetClass, confirmwidget,
X				NULL, 0);
X
X		nwidgets = -1;
X
X		/*
X		 * Confirmation button.
X		 */
X		nargs = 0;
X		SetArg(XtNcallback, confirm_callbacks);
X		widgets[++nwidgets] = XtCreateWidget("confirm",
X				commandWidgetClass, form, args, nargs);
X
X		/*
X		 * Cancellation button.
X		 */
X		nargs = 0;
X		SetArg(XtNcallback, cancel_callbacks);
X		SetArg(XtNfromHoriz, widgets[nwidgets]);
X		widgets[++nwidgets] = XtCreateWidget("cancel",
X				commandWidgetClass, form, args, nargs);
X
X		/*
X		 * Let the shell widget know we're here.
X		 */
X		XtManageChildren(widgets, XtNumber(widgets));
X		XtManageChild(form);
X
X		XtRealizeWidget(confirmwidget);
X		inited = True;
X	}
X	else {
X		/*
X		 * Reset the confirmation box position.
X		 */
X		nargs = 0;
X		SetArg(XtNx, root_x);
X		SetArg(XtNy, root_y);
X		XtSetValues(confirmwidget, args, nargs);
X
X		/*
X		 * Reset the callbacks.
X		 */
X		nargs = 0;
X		SetArg(XtNcallback, confirm_callbacks);
X		XtSetValues(widgets[0], args, nargs);
X
X		nargs = 0;
X		SetArg(XtNcallback, cancel_callbacks);
X		XtSetValues(widgets[1], args, nargs);
X	}
X
X	/*
X	 * Pop up the confirmation box.
X	 */
X	XtPopup(confirmwidget, XtGrabExclusive);
X}
X
X/*
X * ClearConfirm - get rid of the confirmation box.
X */
Xvoid
XClearConfirm()
X{
X	XtPopdown(confirmwidget);
X}
END_OF_FILE
if test 2779 -ne `wc -c <'confirm.c'`; then
    echo shar: \"'confirm.c'\" unpacked with wrong size!
fi
# end of 'confirm.c'
fi
if test -f 'menu.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'menu.c'\"
else
echo shar: Extracting \"'menu.c'\" \(2871 characters\)
sed "s/^X//" >'menu.c' <<'END_OF_FILE'
X#ifndef lint
Xstatic char	*RCSid = "$Header$";
X#endif
X
X/*
X * menu.c - routines to handle the menu.
X *
X * David A. Curry
X * Research Institute for Advanced Computer Science
X * Mail Stop 230-5
X * NASA Ames Research Center
X * Moffett Field, CA 94086
X * davy@riacs.edu
X *
X * $Log$
X */
X#include <X11/StringDefs.h>
X#include <X11/Intrinsic.h>
X#include <X11/Shell.h>
X#include <X11/List.h>
X#include <stdio.h>
X
X#include "xpostit.h"
X
XWidget	menuwidget;
XWidget	listwidget;
X
Xstatic String menustrings[] = {
X#define MenuCreate_1p5x2	0
X	"Create 1.5x2 Note",
X#define MenuCreate_3x3		1
X	"Create 3x3 Note  ",
X#define MenuCreate_3x5		2
X	"Create 3x5 Note  ",
X#define MenuRaiseAll		3
X	"Raise All Notes  ",
X#define MenuLowerAll		4
X	"Lower All Notes  ",
X#define MenuSaveAll		5
X	"Save All Notes   ",
X#define MenuExit		6
X	"Exit             "
X};
X
Xstatic void	LeaveListWidget();
Xstatic void	HandleListSelection();
X
X/*
X * CreateMenuWidget - create the widget used for the menu.
X */
Xvoid
XCreateMenuWidget()
X{
X	Arg args[8];
X	register int nargs;
X	XtCallbackRec callbacks[2];
X
X	/*
X	 * Set the callback.
X	 */
X	bzero(callbacks, sizeof(callbacks));
X	SetCallback(HandleListSelection, NULL);
X
X	/*
X	 * The menu is done with a popup shell.
X	 */
X	menuwidget = XtCreatePopupShell("Menu", overrideShellWidgetClass,
X			toplevel, NULL, 0);
X
X	/*
X	 * Create the list widget.
X	 */
X	nargs = 0;
X	SetArg(XtNdefaultColumns, 1);
X	SetArg(XtNlist, menustrings);
X	SetArg(XtNcallback, callbacks);
X	SetArg(XtNnumberStrings, XtNumber(menustrings));
X
X	listwidget = XtCreateWidget("menu", listWidgetClass, menuwidget,
X			args, nargs);
X
X	/*
X	 * Add an event handler for leaving the list window.
X	 */
X	XtAddEventHandler(listwidget, LeaveWindowMask, False, LeaveListWidget,
X			(caddr_t) NULL);
X
X	/*
X	 * Let the top level shell know we're here.
X	 */
X	XtManageChild(listwidget);
X	XtRealizeWidget(menuwidget);
X}
X
X/*
X * HandleListSelection - callback from list widget to handle a selection.
X */
Xstatic void
XHandleListSelection(w, client_data, call_data)
Xcaddr_t client_data, call_data;
XWidget w;
X{
X	XtListReturnStruct *xlrs;
X
X	xlrs = (XtListReturnStruct *) call_data;
X
X	/*
X	 * Get rid of the menu.
X	 */
X	XtListUnhighlight(listwidget);
X	XtPopdown(menuwidget);
X
X	/*
X	 * Dispatch the command.
X	 */
X	switch (xlrs->index) {
X	case MenuCreate_1p5x2:
X		CreateNewNote(PostItNote_1p5x2);
X		break;
X	case MenuCreate_3x3:
X		CreateNewNote(PostItNote_3x3);
X		break;
X	case MenuCreate_3x5:
X		CreateNewNote(PostItNote_3x5);
X		break;
X	case MenuRaiseAll:
X		RaiseAllNotes();
X		break;
X	case MenuLowerAll:
X		LowerAllNotes();
X		break;
X	case MenuSaveAll:
X		SaveAllNotes();
X		break;
X	case MenuExit:
X		ByeBye();
X		break;
X	}
X}
X
X/*
X * LeaveListWidget - lower the menu when the mouse leaves the list window.
X */
Xstatic void
XLeaveListWidget(w, client_data, event)
Xcaddr_t client_data;
XXEvent *event;
XWidget w;
X{
X	XtListUnhighlight(listwidget);
X	XtPopdown(menuwidget);
X}
END_OF_FILE
if test 2871 -ne `wc -c <'menu.c'`; then
    echo shar: \"'menu.c'\" unpacked with wrong size!
fi
# end of 'menu.c'
fi
if test -f 'note.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'note.c'\"
else
echo shar: Extracting \"'note.c'\" \(14060 characters\)
sed "s/^X//" >'note.c' <<'END_OF_FILE'
X#ifndef lint
Xstatic char	*RCSid = "$Header$";
X#endif
X
X/*
X * note.c - routines for handling notes.
X *
X * David A. Curry
X * Research Institute for Advanced Computer Science
X * Mail Stop 230-5
X * NASA Ames Research Center
X * Moffett Field, CA 94086
X * davy@riacs.edu
X *
X * $Log$
X */
X#include <X11/StringDefs.h>
X#include <X11/Intrinsic.h>
X#include <X11/AsciiText.h>
X#include <X11/Command.h>
X#include <X11/Shell.h>
X#include <X11/Form.h>
X#include <sys/param.h>
X#include <sys/dir.h>
X#include <stdio.h>
X
X#include "xpostit.h"
X
Xstatic PostItNote	*notes = NULL;
X
Xstatic PostItNote	*FindNote();
Xstatic PostItNote	*AllocNote();
X
Xstatic void		SaveNote();
Xstatic void		EraseNote();
Xstatic void		DestroyNote();
Xstatic void		CancelErase();
Xstatic void		ConfirmErase();
Xstatic void		CancelDestroy();
Xstatic void		ConfirmDestroy();
Xstatic void		MakeNoteWidget();
Xstatic void		SetTextOptions();
X
X/*
X * CreateNewNote - create a new note of the specified size.
X */
Xvoid
XCreateNewNote(size)
Xint size;
X{
X	static int hpi = 0;
X	static int wpi = 0;
X	register PostItNote *pn;
X	register int hmm, wmm, hpixel, wpixel;
X
X	/*
X	 * Find out the number of pixels per inch on the screen.  We
X	 * can get the number of pixels, and the size in millimeters.
X	 * Then we convert to pixels/inch using the formula
X	 *
X	 *       2.54 cm     10 mm     pixels     pixels
X	 *	--------- x ------- x -------- = --------
X	 *	  inch        cm         mm        inch
X	 *
X	 * The only problem with this is that some servers (like Xsun)
X	 * lie about what these numbers really are.
X	 */
X	if ((hpi == 0) || (wpi == 0)) {
X		hpixel = DisplayHeight(display, DefaultScreen(display));
X		wpixel = DisplayWidth(display, DefaultScreen(display));
X
X		hmm = DisplayHeightMM(display, DefaultScreen(display));
X		wmm = DisplayWidthMM(display, DefaultScreen(display));
X
X		hpi = (int) ((25.4 * hpixel) / (float) hmm + 0.5);
X		wpi = (int) ((25.4 * wpixel) / (float) wmm + 0.5);
X	}
X
X	/*
X	 * Calculate sizes for the note.
X	 */
X	switch (size) {
X	case PostItNote_1p5x2:
X		hpixel = 1.5 * hpi;
X		wpixel = 2 * wpi;
X		break;
X	case PostItNote_3x3:
X		hpixel = 3 * hpi;
X		wpixel = 3 * wpi;
X		break;
X	case PostItNote_3x5:
X		hpixel = 3 * hpi;
X		wpixel = 5 * wpi;
X		break;
X	}
X
X	/*
X	 * Allocate a new note structure.
X	 */
X	pn = AllocNote(NewIndex);
X
X	/*
X	 * Set the text window size.
X	 */
X	pn->pn_textwidth = wpixel;
X	pn->pn_textheight = hpixel;
X
X	/*
X	 * Make the widget for the note.
X	 */
X	MakeNoteWidget(pn);
X}
X
X/*
X * LoadSavedNotes - load in the notes the user has saved.
X */
Xvoid
XLoadSavedNotes()
X{
X	DIR *dp;
X	FILE *fp;
X	char *realloc();
X	register PostItNote *pn;
X	register struct direct *d;
X	char buf[BUFSIZ], fname[MAXPATHLEN];
X	int n, len, nlen, shellx, shelly, texth, textw;
X
X	/*
X	 * Try to open the directory.
X	 */
X	if ((dp = opendir(app_res.note_dir)) == NULL)
X		return;
X
X	nlen = strlen(PostItNoteFname);
X
X	/*
X	 * For each entry...
X	 */
X	while ((d = readdir(dp)) != NULL) {
X		/*
X		 * Skip over anything which doesn't match our
X		 * file naming scheme.
X		 */
X		if (strncmp(d->d_name, PostItNoteFname, nlen) != 0)
X			continue;
X
X		/*
X		 * Make the full path name.
X		 */
X		sprintf(fname, "%s/%s", app_res.note_dir, d->d_name);
X
X		/*
X		 * Open the file.
X		 */
X		if ((fp = fopen(fname, "r")) == NULL)
X			continue;
X
X		/*
X		 * Look for the magic cookie identifying this as
X		 * a Post-It note.
X		 */
X		if ((fscanf(fp, "%s", buf) == EOF) ||
X		    (strcmp(buf, PostItNoteMagic) != 0)) {
X			fclose(fp);
X			continue;
X		}
X
X		/*
X		 * Get the note position and size information.
X		 */
X		fgets(buf, sizeof(buf), fp);
X
X		n = sscanf(buf, "%d %d %d %d %d", &shellx, &shelly, &texth,
X				&textw, &len);
X
X		/*
X		 * Bad format; skip it.
X		 */
X		if (n != 5) {
X			fclose(fp);
X			continue;
X		}
X
X		/*
X		 * Get the index number of this note.
X		 */
X		n = atoi(&(d->d_name[nlen]));
X
X		/*
X		 * Get a note structure.
X		 */
X		pn = AllocNote(n);
X
X		/*
X		 * Set the information.
X		 */
X		pn->pn_shellx = shellx;
X		pn->pn_shelly = shelly;
X		pn->pn_textwidth = textw;
X		pn->pn_textheight = texth;
X		pn->pn_positionit = True;
X
X		/*
X		 * Save the file name.
X		 */
X		pn->pn_file = SafeAlloc(strlen(fname) + 1);
X		strcpy(pn->pn_file, fname);
X
X		/*
X		 * If we need a bigger buffer than the default,
X		 * get one.
X		 */
X		if (len >= pn->pn_textsize) {
X			n = (len + app_res.buf_size - 1) / app_res.buf_size;
X			n = n * app_res.buf_size;
X
X			if ((pn->pn_text = realloc(pn->pn_text, n)) == NULL) {
X				fprintf(stderr, "xpostit: out of memory.\n");
X				ByeBye();
X			}
X
X			pn->pn_textsize = n;
X		}
X
X		/*
X		 * Read in the text.
X		 */
X		fread(pn->pn_text, sizeof(char), len, fp);
X		fclose(fp);
X
X		/*
X		 * Make a widget for this note.
X		 */
X		MakeNoteWidget(pn);
X	}
X
X	closedir(dp);
X}
X
X/*
X * RaiseAllNotes - raise all the notes by raising their shell windows.
X */
Xvoid
XRaiseAllNotes()
X{
X	register PostItNote *pn;
X
X	for (pn = notes; pn != NULL; pn = pn->pn_next)
X		XRaiseWindow(display, XtWindow(pn->pn_shellwidget));
X}
X
X/*
X * LowerAllNotes - lower all the notes by lowering their shell windows.
X */
Xvoid
XLowerAllNotes()
X{
X	register PostItNote *pn;
X
X	for (pn = notes; pn != NULL; pn = pn->pn_next)
X		XLowerWindow(display, XtWindow(pn->pn_shellwidget));
X}
X
X/*
X * SaveAllNotes - save all the notes.
X */
Xvoid
XSaveAllNotes()
X{
X	register PostItNote *pn;
X
X	for (pn = notes; pn != NULL; pn = pn->pn_next)
X		SaveNote(pn->pn_shellwidget, (caddr_t) pn->pn_index, 0);
X}
X
X/*
X * MakeNoteWidget - make a widget for a Post-It note.
X */
Xstatic void
XMakeNoteWidget(pn)
XPostItNote *pn;
X{
X	Arg args[8];
X	int options;
X	Widget form, widgets[4];
X	XtCallbackRec callbacks[2];
X	register int nargs, nwidgets;
X
X	bzero(callbacks, sizeof(callbacks));
X	nargs = 0;
X
X	/*
X	 * If the shell window coordinates are valid, use them.
X	 */
X	if (pn->pn_positionit) {
X		SetArg(XtNx, pn->pn_shellx);
X		SetArg(XtNy, pn->pn_shelly);
X	}
X
X	/*
X	 * Make the shell widget for this note.  We just use
X	 * a pop-up shell for this.
X	 */
X	pn->pn_shellwidget = XtCreatePopupShell("PostItNote",
X			wmShellWidgetClass, toplevel, args, nargs);
X
X	/*
X	 * Make a form widget.
X	 */
X	form = XtCreateWidget("form", formWidgetClass, pn->pn_shellwidget,
X			NULL, 0);
X
X	nwidgets = -1;
X
X	/*
X	 * Put each button into the shell widget.  The second and third
X	 * buttons will position themselves relative to the first one;
X	 * the first one will position itself relative to the edge of
X	 * the form.
X	 */
X	SetCallback(SaveNote, pn->pn_index);
X
X	nargs = 0;
X	SetArg(XtNcallback, callbacks);
X	widgets[++nwidgets] = XtCreateWidget("save", commandWidgetClass,
X			form, args, nargs);
X
X	SetCallback(EraseNote, pn->pn_index);
X
X	nargs = 0;
X	SetArg(XtNcallback, callbacks);
X	SetArg(XtNfromHoriz, widgets[nwidgets]);
X	widgets[++nwidgets] = XtCreateWidget("erase", commandWidgetClass,
X			form, args, nargs);
X
X	SetCallback(DestroyNote, pn->pn_index);
X
X	nargs = 0;
X	SetArg(XtNcallback, callbacks);
X	SetArg(XtNfromHoriz, widgets[nwidgets]);
X	widgets[++nwidgets] = XtCreateWidget("destroy", commandWidgetClass,
X			form, args, nargs);
X
X	/*
X	 * Set text window options.
X	 */
X	SetTextOptions(&options);
X
X	/*
X	 * Create the text window.
X	 */
X	nargs = 0;
X	SetArg(XtNstring, pn->pn_text);
X	SetArg(XtNtextOptions, options);
X	SetArg(XtNeditType, XttextEdit);
X	SetArg(XtNlength, pn->pn_textsize);
X	SetArg(XtNwidth, pn->pn_textwidth);
X	SetArg(XtNheight, pn->pn_textheight);
X	SetArg(XtNfromVert, widgets[nwidgets]);
X	widgets[++nwidgets] = XtCreateWidget("text", asciiStringWidgetClass,
X			form, args, nargs);
X
X	/*
X	 * Save the text widget.
X	 */
X	pn->pn_textwidget = widgets[nwidgets];
X
X	/*
X	 * Let the top level shell know all these guys are here.
X	 */
X	XtManageChildren(widgets, XtNumber(widgets));
X	XtManageChild(form);
X
X	/*
X	 * Realize the note and pop it up.
X	 */
X	XtRealizeWidget(pn->pn_shellwidget);
X	XtPopup(pn->pn_shellwidget, XtGrabNone);
X}
X
X/*
X * SaveNote - save a note to a file.
X */
Xstatic void
XSaveNote(w, client_data, call_data)
Xcaddr_t client_data, call_data;
XWidget w;
X{
X	FILE *fp;
X	char *MakeFname();
X	XSizeHints sizehints;
X	register PostItNote *pn;
X	int len, shellx, shelly, texth, textw;
X
X	/*
X	 * Find the note we're saving.
X	 */
X	if ((pn = FindNote((int) client_data)) == NULL)
X		return;
X
X	/*
X	 * If it doesn't have a file name, make one.
X	 */
X	if (pn->pn_file == NULL)
X		pn->pn_file = MakeFname(pn->pn_index);
X
X	/*
X	 * Create the file.
X	 */
X	if ((fp = fopen(pn->pn_file, "w")) == NULL) {
X		fprintf(stderr, "xpostit: ");
X		perror(pn->pn_file);
X		return;
X	}
X
X	/*
X	 * Get the position of the shell window.
X	 */
X	XGetNormalHints(display, XtWindow(pn->pn_shellwidget), &sizehints);
X	shellx = sizehints.x;
X	shelly = sizehints.y;
X
X	/*
X	 * Get the size of the text window.
X	 */
X	XGetNormalHints(display, XtWindow(pn->pn_textwidget), &sizehints);
X	texth = sizehints.height;
X	textw = sizehints.width;
X
X	/*
X	 * Get the length of the text in the window.
X	 */
X	len = strlen(pn->pn_text);
X
X	/*
X	 * Print out the information needed to recreate the note.
X	 */
X	fprintf(fp, "%s %d %d %d %d %d\n", PostItNoteMagic, shellx, shelly,
X			texth, textw, len);
X
X	/*
X	 * Write out the text of the note.
X	 */
X	if (len)
X		fwrite(pn->pn_text, sizeof(char), len, fp);
X
X	fclose(fp);
X}
X
X/*
X * EraseNote - erase all the text in a note.
X */
Xstatic void
XEraseNote(w, client_data, call_data)
Xcaddr_t client_data, call_data;
XWidget w;
X{
X	PostItNote *pn;
X	XtCallbackRec cancel[2], confirm[2];
X
X	bzero(confirm, sizeof(confirm));
X	bzero(cancel, sizeof(cancel));
X
X	/*
X	 * Find the note we're erasing.
X	 */
X	if ((pn = FindNote((int) client_data)) == NULL)
X		return;
X
X	/*
X	 * If there's nothing in the window, then there's
X	 * no need to erase it.
X	 */
X	if (strlen(pn->pn_text) == 0)
X		return;
X
X	confirm[0].callback = ConfirmErase;
X	confirm[0].closure = (caddr_t) pn->pn_index;
X	cancel[0].callback = CancelErase;
X	cancel[0].closure = (caddr_t) pn->pn_index;
X
X	/*
X	 * Get confirmation of what they want to do.
X	 */
X	ConfirmIt(confirm, cancel);
X}
X
X/*
X * DestroyNote - destroy a note.
X */
Xstatic void
XDestroyNote(w, client_data, call_data)
Xcaddr_t client_data, call_data;
XWidget w;
X{
X	PostItNote *pn;
X	XtCallbackRec cancel[2], confirm[2];
X
X	bzero(confirm, sizeof(confirm));
X	bzero(cancel, sizeof(cancel));
X
X	/*
X	 * Find the note we're destroying.
X	 */
X	if ((pn = FindNote((int) client_data)) == NULL)
X		return;
X
X	confirm[0].callback = ConfirmDestroy;
X	confirm[0].closure = (caddr_t) pn->pn_index;
X	cancel[0].callback = CancelDestroy;
X	cancel[0].closure = (caddr_t) pn->pn_index;
X
X	/*
X	 * Get confirmation of what they want to do.
X	 */
X	ConfirmIt(confirm, cancel);
X}
X
X/*
X * ConfirmErase - callback for erase confirmation.
X */
Xstatic void
XConfirmErase(w, client_data, call_data)
Xcaddr_t client_data, call_data;
XWidget w;
X{
X	XtTextPosition pos = 0;
X	register PostItNote *pn;
X
X	/*
X	 * Get rid of the confirmation box.
X	 */
X	ClearConfirm();
X
X	/*
X	 * Find the note we're erasing.
X	 */
X	if ((pn = FindNote((int) client_data)) == NULL)
X		return;
X
X	/*
X	 * This is a kludge.  They should have provided
X	 * an XtTextErase function.
X	 */
X	XtTextDisableRedisplay(pn->pn_textwidget);
X
X	bzero(pn->pn_text, pn->pn_textsize);
X
X	XtTextSetInsertionPoint(pn->pn_textwidget, pos);
X	XtTextSetLastPos(pn->pn_textwidget, pos);
X	XtTextEnableRedisplay(pn->pn_textwidget);
X}
X
X/*
X * CancelErase - callback for erase cancellation.
X */
Xstatic void
XCancelErase(w, client_data, call_data)
Xcaddr_t client_data, call_data;
XWidget w;
X{
X	/*
X	 * Get rid of the confirmation box.
X	 */
X	ClearConfirm();
X}
X
X/*
X * ConfirmDestroy - callback for destroy confirmation.
X */
Xstatic void
XConfirmDestroy(w, client_data, call_data)
Xcaddr_t client_data, call_data;
XWidget w;
X{
X	register PostItNote *pn, *prev;
X
X	/*
X	 * Get rid of the confirmation box.
X	 */
X	ClearConfirm();
X
X	/*
X	 * Find the note we're destroying.
X	 */
X	if ((pn = FindNote((int) client_data)) == NULL)
X		return;
X
X	/*
X	 * Get rid of the widgets for this note.
X	 */
X	XtPopdown(pn->pn_shellwidget);
X	XtDestroyWidget(pn->pn_shellwidget);
X
X	/*
X	 * Get rid of the note structure.
X	 */
X	if (pn != notes) {
X		for (prev = notes; prev->pn_next; prev = prev->pn_next) {
X			if (prev->pn_next == pn)
X				break;
X		}
X
X		prev->pn_next = pn->pn_next;
X	}
X	else {
X		notes = pn->pn_next;
X	}
X
X	/*
X	 * Get rid of the file.
X	 */
X	if (pn->pn_file) {
X		unlink(pn->pn_file);
X		free(pn->pn_file);
X	}
X
X	/*
X	 * Free the memory we used.
X	 */
X	free(pn->pn_text);
X	free(pn);
X}
X
X/*
X * CancelDestroy - callback for destroy cancellation.
X */
Xstatic void
XCancelDestroy(w, client_data, call_data)
Xcaddr_t client_data, call_data;
XWidget w;
X{
X	/*
X	 * Get rid of the confirmation box.
X	 */
X	ClearConfirm();
X}
X
X/*
X * AllocNote - allocate a new note structure and insert in into the
X *	       list of notes.
X */
Xstatic PostItNote *
XAllocNote(index)
Xint index;
X{
X	register PostItNote *pn;
X
X	/*
X	 * Allocate a structure.
X	 */
X	if (notes == NULL) {
X		notes = (PostItNote *) SafeAlloc(sizeof(PostItNote));
X		pn = notes;
X	}
X	else {
X		for (pn = notes; pn->pn_next != NULL; pn = pn->pn_next)
X			;
X
X		pn->pn_next = (PostItNote *) SafeAlloc(sizeof(PostItNote));
X		pn = pn->pn_next;
X	}
X
X	/*
X	 * Initialize the note.
X	 */
X	pn->pn_positionit = False;
X	pn->pn_textsize = app_res.buf_size;
X	pn->pn_text = SafeAlloc(pn->pn_textsize);
X
X	/*
X	 * If the index number was given, use it.  Otherwise,
X	 * get a new index number.
X	 */
X	pn->pn_index = (index == NewIndex ? NoteIndex() : index);
X
X	return(pn);
X}
X
X/*
X * FindNote - find the note structure with the given index number.
X */
Xstatic PostItNote *
XFindNote(index)
Xregister int index;
X{
X	register PostItNote *pn;
X
X	for (pn = notes; pn != NULL; pn = pn->pn_next) {
X		if (pn->pn_index == index)
X			return(pn);
X	}
X
X	return(NULL);
X}
X
X/*
X * SetTextOptions - set text window options from application resources.
X */
Xstatic void
XSetTextOptions(options)
Xregister int *options;
X{
X	*options = editable | wordBreak;
X
X	if (app_res.scroll_ovf)
X		*options |= scrollOnOverflow;
X
X	if (app_res.scroll_bar)
X		*options |= scrollVertical;
X}
X
X/*
X * NoteIndex - find the lowest free index number.
X */
Xstatic int
XNoteIndex()
X{
X	register int index;
X	register PostItNote *pn;
X
X	/*
X	 * This is O(n**2), but the list should be small.
X	 */
X	for (index = 1; ; index++) {
X		if ((pn = FindNote(index)) == NULL)
X			return(index);
X	}
X}
END_OF_FILE
if test 14060 -ne `wc -c <'note.c'`; then
    echo shar: \"'note.c'\" unpacked with wrong size!
fi
# end of 'note.c'
fi
if test -f 'plaid.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'plaid.c'\"
else
echo shar: Extracting \"'plaid.c'\" \(2507 characters\)
sed "s/^X//" >'plaid.c' <<'END_OF_FILE'
X#ifndef lint
Xstatic char	*RCSid = "$Header$";
X#endif
X
X/*
X * plaid.c - routines for manipulating the plaid widget.
X *
X * David A. Curry
X * Research Institute for Advanced Computer Science
X * Mail Stop 230-5
X * NASA Ames Research Center
X * Moffett Field, CA 94086
X * davy@riacs.edu
X *
X * $Log$
X */
X#include <X11/StringDefs.h>
X#include <X11/Intrinsic.h>
X#include <stdio.h>
X
X#include "xpostit.h"
X#include "Plaid.h"
X
XWidget		plaidwidget;
X
Xstatic void	HandlePlaidButton();
X
X/*
X * CreatePlaidWidget - create the plaid widget.
X */
Xvoid
XCreatePlaidWidget()
X{
X	Arg args[4];
X	register int nargs;
X	XtCallbackRec callbacks[2];
X
X	/*
X	 * Set the callback.
X	 */
X	bzero(callbacks, sizeof(callbacks));
X	SetCallback(HandlePlaidButton, NULL);
X
X	/*
X	 * Create the plaid widget.
X	 */
X	nargs = 0;
X	SetArg(XtNcallback, callbacks);
X	plaidwidget = XtCreateWidget("plaid", plaidWidgetClass, toplevel,
X			args, nargs);
X
X	/*
X	 * Get the width and height of the widget.
X	 */
X	nargs = 0;
X	SetArg(XtNwidth, NULL);
X	SetArg(XtNheight, NULL);
X	XtGetValues(plaidwidget, args, nargs);
X
X	/*
X	 * If the user didn't set them, then we
X	 * should set them to the defaults.
X	 */
X	if ((args[0].value == 0) || (args[1].value == 0)) {
X		if (args[0].value == 0)
X			XtSetArg(args[0], XtNwidth, DefaultPlaidWidth);
X
X		if (args[1].value == 0)
X			XtSetArg(args[1], XtNheight, DefaultPlaidHeight);
X
X		XtSetValues(plaidwidget, args, nargs);
X	}
X
X	/*
X	 * Inform the application shell we're here.
X	 */
X	XtManageChild(plaidwidget);
X}
X
X/*
X * HandlePlaidButton - callback for the plaid widget to handle buttons.
X */
Xstatic void
XHandlePlaidButton(w, client_data, call_data)
Xcaddr_t client_data, call_data;
XWidget w;
X{
X	Arg args[4];
X	register int nargs;
X	register XEvent *event;
X	register Position x, y;
X
X	/*
X	 * Get the event.
X	 */
X	event = (XEvent *) call_data;
X
X	/*
X	 * We're only interested in button presses.
X	 */
X	if (event->type != ButtonPress)
X		return;
X
X	/*
X	 * Dispatch a function for this button.
X	 */
X	switch (event->xbutton.button) {
X	case Button1:		/* left */
X		RaiseAllNotes();
X		break;
X	case Button2:		/* middle */
X		LowerAllNotes();
X		break;
X	case Button3:		/* right */
X		/*
X		 * Get position of mouse so we can put
X		 * the menu there.
X		 */
X		x = event->xbutton.x_root;
X		y = event->xbutton.y_root;
X
X		/*
X		 * Move the popup to that location.
X		 */
X		nargs = 0;
X		SetArg(XtNx, x);
X		SetArg(XtNy, y);
X		XtSetValues(menuwidget, args, nargs);
X
X		/*
X		 * Bring up the menu.
X		 */
X		XtPopup(menuwidget, XtGrabExclusive);
X		break;
X	default:
X		break;
X	}
X}
END_OF_FILE
if test 2507 -ne `wc -c <'plaid.c'`; then
    echo shar: \"'plaid.c'\" unpacked with wrong size!
fi
# end of 'plaid.c'
fi
if test -f 'xpostit.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xpostit.c'\"
else
echo shar: Extracting \"'xpostit.c'\" \(4779 characters\)
sed "s/^X//" >'xpostit.c' <<'END_OF_FILE'
X#ifndef lint
Xstatic char	*RCSid = "$Header$";
X#endif
X
X/*
X * xpostit.c - Post-It Notes for the X Window System.
X *
X * Based on an X10R4 application.  This one is for X11R3 and uses the
X * Xt toolkit and the Athena widgets.
X *
X * All the "#ifdef notdef" stuff below is what *should* be used to start
X * this up.  This is because allegedly, XtInitialize() and XtMainLoop()
X * are obsolete.  Unfortunately, since pieces of the widgets use the
X * defaultAppContext instead of the user-supplied one, the "right" way
X * doesn't work.  Sigh.
X *
X * David A. Curry
X * Research Institute for Advanced Computer Science
X * Mail Stop 230-5
X * NASA Ames Research Center
X * Moffett Field, CA 94086
X * davy@riacs.edu
X *
X * $Log$
X */
X#include <X11/StringDefs.h>
X#include <X11/Intrinsic.h>
X#include <X11/Shell.h>
X#include <signal.h>
X#include <stdio.h>
X
X#include "xpostit.h"
X
X/*
X * Command line options and the resources they set.
X */
Xstatic XrmOptionDescRec options[] = {
X    { "-bs",	".bufSize",		XrmoptionSepArg,	NULL },
X    { "-dir",	".noteDir",		XrmoptionSepArg,	NULL },
X    { "-sb",	".scrollBar",		XrmoptionNoArg,		"true" },
X    { "-so",	".scrollOnOverflow",	XrmoptionNoArg,		"true" },
X    { "-sv",	".saveNotes",		XrmoptionNoArg,		"true" }
X};
X
X/*
X * Resources we maintain besides those maintained by the toolkit.
X */
Xstatic XtResource resources[] = {
X#define offset(field)	XtOffset(AppResPtr,field)
X    { "bufSize", "BufSize", XtRInt, sizeof(int),
X      offset(buf_size), XtRImmediate, (caddr_t) DefaultBufSize },
X    { "noteDir", "NoteDir", XtRString, sizeof(String),
X      offset(note_dir), XtRString, DefaultNoteDir },
X    { "saveNotes", "SaveNotes", XtRBoolean, sizeof(Boolean),
X      offset(save_notes), XtRImmediate, (caddr_t) False },
X    { "scrollBar", "Scroll", XtRBoolean, sizeof(Boolean),
X      offset(scroll_bar), XtRImmediate, (caddr_t) False },
X    { "scrollOnOverflow", "Scroll", XtRBoolean, sizeof(Boolean),
X      offset(scroll_ovf), XtRImmediate, (caddr_t) False }
X#undef offset
X};
X
XAppRes	app_res;		/* xpostit application resources	*/
XWidget	toplevel;		/* top level application shell widget	*/
XScreen	*screen;		/* pointer to the screen of the display	*/
XDisplay	*display;		/* pointer to the display we're on	*/
X
Xvoid
Xmain(argc, argv)
Xchar **argv;
Xint argc;
X{
X#ifdef notdef
X	Arg args[4];
X	char *appname;
X	char *rindex();
X	char **saved_argv;
X	XtAppContext appcontext;
X#endif
X	Boolean setsigs = False;
X#ifdef notdef
X	register int nargs, saved_argc;
X#endif
X
X	/*
X	 * Ignore signals for now, but record whether they were
X	 * already ignored or not so we can catch them later if
X	 * need be.
X	 */
X	if ((signal(SIGQUIT, SIG_IGN) != SIG_IGN) &&
X	    (signal(SIGINT, SIG_IGN) != SIG_IGN))
X		setsigs = True;
X
X#ifdef notdef
X	/*
X	 * Save arguments for setting in the WM_COMMAND property
X	 * of the application shell.
X	 */
X	saved_argv = (char **) SafeAlloc((argc + 1) * sizeof(char *));
X
X	for (saved_argc = 0; saved_argc < argc; saved_argc++)
X		saved_argv[saved_argc] = argv[saved_argc];
X	saved_argv[saved_argc] = NULL;
X
X	/*
X	 * Get application name.
X	 */
X	if ((appname = rindex(*argv, '/')) == NULL)
X		appname = *argv;
X	else
X		appname++;
X
X	/*
X	 * Initialize the toolkit.
X	 */
X	XtToolkitInitialize();
X
X	/*
X	 * Create an application context for our application.
X	 */
X	appcontext = XtCreateApplicationContext();
X
X	/*
X	 * Open and initialize the display.
X	 */
X	display = XtOpenDisplay(appcontext, NULL, appname, PostItNoteClass,
X			options, XtNumber(options), &argc, argv);
X
X	screen = DefaultScreenOfDisplay(display);
X
X	nargs = 0;
X	SetArg(XtNscreen, screen);
X	SetArg(XtNargc, saved_argc);
X	SetArg(XtNargv, saved_argv);
X	
X	/*
X	 * Create the top level application shell.
X	 */
X	toplevel = XtAppCreateShell(NULL, PostItNoteClass,
X			applicationShellWidgetClass, display, args, nargs);
X#else
X	toplevel = XtInitialize("main", "XPostit", options, XtNumber(options),
X			&argc, argv);
X
X	display = XtDisplay(toplevel);
X	screen = DefaultScreenOfDisplay(display);
X#endif
X
X	/*
X	 * If we need to handle signals, do it now.
X	 */
X	if (setsigs) {
X		signal(SIGQUIT, ByeBye);
X		signal(SIGINT, ByeBye);
X	}
X
X	/*
X	 * Now get any resources we're interested in.
X	 */
X	XtGetApplicationResources(toplevel, &app_res, resources,
X			XtNumber(resources), argv, argc);
X
X	/*
X	 * Construct the path to the directory notes are
X	 * stored in.
X	 */
X	SetNoteDir();
X
X	/*
X	 * Create the plaid and menu widgets.
X	 */
X	CreatePlaidWidget();
X	CreateMenuWidget();
X
X	/*
X	 * Realize the top level and flush the server, which will
X	 * let the user position the plaid window and map it.
X	 */
X	XtRealizeWidget(toplevel);
X	XFlush(display);
X
X	/*
X	 * Load the notes the user has saved, and create widgets
X	 * for them.
X	 */
X	LoadSavedNotes();
X
X	/*
X	 * Never returns.
X	 */
X#ifdef notdef
X	XtAppMainLoop(appcontext);
X#else
X	XtMainLoop();
X#endif
X}
END_OF_FILE
if test 4779 -ne `wc -c <'xpostit.c'`; then
    echo shar: \"'xpostit.c'\" unpacked with wrong size!
fi
# end of 'xpostit.c'
fi
if test -f 'xpostit.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xpostit.h'\"
else
echo shar: Extracting \"'xpostit.h'\" \(2652 characters\)
sed "s/^X//" >'xpostit.h' <<'END_OF_FILE'
X/*
X * $Header$
X *
X * xpostit.h - declarations for xpostit.
X *
X * David A. Curry
X * Research Institute for Advanced Computer Science
X * Mail Stop 230-5
X * NASA Ames Research Center
X * Moffett Field, CA 94086
X * davy@riacs.edu
X *
X * $Log$
X */
X
X/*
X * Default values.
X */
X#define DefaultBufSize		1024
X#define DefaultNoteDir		".postitnotes"
X#define DefaultPlaidWidth	64
X#define DefaultPlaidHeight	64
X
X/*
X * Post-It Note sizes.
X */
X#define PostItNote_1p5x2	0
X#define PostItNote_3x3		1
X#define PostItNote_3x5		2
X
X/*
X * Post-It Note file information.
X */
X#define PostItNoteMagic		"%!<postitnote>"
X#define PostItNoteFname		"note"
X
X/*
X * Application class.
X */
X#define PostItNoteClass		"XPostit"
X
X/*
X * Request for a new note index number.
X */
X#define NewIndex		-1
X
X/*
X * Just in case.
X */
X#ifndef MAXPATHLEN
X#define MAXPATHLEN	1024
X#endif
X
X/*
X * Useful macros.
X */
X#define SetArg(which, val)	XtSetArg(args[nargs], (which),\
X					(XtArgVal) (val)); nargs++
X#define SetCallback(which, val)	callbacks[0].callback = (which); \
X				callbacks[0].closure = (caddr_t) (val)
X
X/*
X * The Post-It Note record.  One of these is allocated
X * for each note created.
X */
Xtypedef struct _PostItNote {
X	Widget	pn_shellwidget;		/* shell widget holding it all	*/
X	Widget	pn_textwidget;		/* text widget of the note	*/
X
X	char	*pn_file;		/* file note will be saved in	*/
X	char	*pn_text;		/* buffer holding text of note	*/
X
X	int	pn_index;		/* index number of note		*/
X	int	pn_shellx;		/* x coord of shell widget	*/
X	int	pn_shelly;		/* y coord of shell widget	*/
X	int	pn_textsize;		/* size of pn_text in chars	*/
X	int	pn_textwidth;		/* width of text widget window	*/
X	int	pn_textheight;		/* height of text widget window	*/
X
X	Boolean	pn_positionit;		/* true if shellx/shelly valid	*/
X
X	struct	_PostItNote *pn_next;	/* pointer to next note record	*/
X} PostItNote;
X
X/*
X * The resource record, for holding resources specific to xpostit.
X */
Xtypedef struct {
X	int	buf_size;		/* size of pn_text to be used	*/
X	String	note_dir;		/* path to note directory	*/
X	Boolean	scroll_ovf;		/* set scroll on overflow	*/
X	Boolean	scroll_bar;		/* turn on scroll bars		*/
X	Boolean save_notes;		/* save notes on exit		*/
X} AppRes, *AppResPtr;
X
X/*
X * External variable declarations.
X */
Xextern	AppRes app_res;
X
Xextern	Screen *screen;
Xextern	Display *display;
X
Xextern	Widget toplevel;
Xextern	Widget listwidget;
Xextern	Widget menuwidget;
Xextern	Widget plaidwidget;
X
X/*
X * Function declarations.
X */
Xchar	*SafeAlloc();
X
Xvoid	ByeBye();
Xvoid	ConfirmIt();
Xvoid	ClearConfirm();
Xvoid	SaveAllNotes();
Xvoid	RaiseAllNotes();
Xvoid	LowerAllNotes();
Xvoid	CreateNewNote();
Xvoid	CreateMenuWidget();
Xvoid	CreatePlaidWidget();
END_OF_FILE
if test 2652 -ne `wc -c <'xpostit.h'`; then
    echo shar: \"'xpostit.h'\" unpacked with wrong size!
fi
# end of 'xpostit.h'
fi
if test -f 'xpostit.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xpostit.man'\"
else
echo shar: Extracting \"'xpostit.man'\" \(8327 characters\)
sed "s/^X//" >'xpostit.man' <<'END_OF_FILE'
X.TH XPOSTIT 1 "2 January 1989" RIACS/X11R3
X.SH NAME
Xxpostit \- X window system Post-it\(rg notes
X.SH SYNOPSIS
X.B xpostit
X[
X.I \-toolkitoptions ...
X] [
X.I \-options ...
X]
X.SH DESCRIPTION
X.I Xpostit
Xprovides a mechanism for manipulating on-screen Post-it\(rg notes.
XAll three sizes of Post-it notes may be displayed,
Xedited,
Xand saved to disk files.
XIn addition,
Xany on-screen note may be resized to any arbitrary size either when it is
Xcreated or at a later time.
X.PP
XWhen
X.I xpostit
Xis first invoked,
Xit creates a small window with a plaid background.
XThis is the control window for
X.IR xpostit .
XAdditionally,
Xif any notes were stored in the save directory (see below),
Xthese will be placed on the screen at their last locations.
XEach Post-it note,
Xwhen created,
Xmakes another window on the screen.
X.I Xpostit
Xis controlled using the mouse buttons and a menu.
XThe Post-it notes are controlled using buttons (Command widgets).
X.SH OPTIONS
X.PP
X.I Xpostit
Xaccepts all of the standard X Toolkit command line options along with the
Xadditional options listed below.
X.TP 8
X.BI \-bs " number"
XSpecifies the size of the character buffer in which to save each Post-it
Xnote.
XA note may not contain more than this number of characters,
Xincluding newlines.
XThe default is 1024.
X.TP 8
X.BI \-dir " path"
XSpecifies the path name of the directory in which to store saved Post-it notes.
XIf
X.I path
Xbegins with a `/' it is taken as-is;
Xif it does not begin with a `/',
Xthe path is taken relative to the home directory.
XThe named directory must already exist if notes are to be saved in it.
XThe default is
X.IR \&.postitnotes .
X.TP 8
X.B \-sb
XEnables scroll-bars.
XIf specified,
Xa scroll bar will be attached to each Post-it note.
X.TP 8
X.B \-so
XEnables scroll-on-overflow.
XWhen specified,
Xthis option tells
X.I xpostit
Xto scroll the text of a Post-it note upward when the bottom of the window
Xis reached.
X.TP 8
X.B \-sv
XEnables save-on-exit.
XWhen specified,
Xthis option tells
X.I xpostit
Xto save all Post-it notes to disk files when exiting.
XIf not specified,
Xnotes will only be saved to disk files when saved manually by the user.
X.SH "WIDGET USAGE"
X.PP
X.I Xpostit
Xuses several widget types to construct the objects it uses.
X.PP
XThe control window is made up of a Plaid widget called ``plaid''.
X.PP
XThe menu is a pop-up shell called ``Menu'',
Xcontaining a List widget called ``menu''.
X.PP
XEach Post-it note is a pop-up shell called ``PostItNote'',
Xcontaining a Form widget called ``form''
Xwhich contains a Text widget called ``text'',
Xand three Command widgets called ``save'',
X``erase'',
Xand ``destroy''.
X.PP
XThe confirmation box is a pop-up shell called ``Confirm'',
Xcontaining a Form widget called ``form''
Xwhich contains two Command widgets called ``confirm'' and ``cancel''.
X.SH "X DEFAULTS"
X.PP
X.I Xpostit
Xunderstands all of the core X Toolkit resource names and classes as well
Xas those listed below,
Xwhich are all of class
X.BR XPostit .
X.TP 8
X.B \&.bufSize
XSpecifies the size of the character buffer used to store a Post-it note.
XThe default is 1024.
X.TP 8
X.B \&.noteDir
XSpecifies the path name of the directory in which to store saved notes.
XThe default is
X.IR \&.postitnotes .
X.TP 8
X.B \&.saveNotes
XControls the state of the save-on-exit option.
XThe default is
X.BR false .
X.TP 8
X.B \&.scrollBar
XControls placing scroll bars on Post-it notes.
XThe default is
X.BR false .
X.TP 8
X.B \&.scrollOnOverflow
XControls whether or not a note window should be scrolled when the bottom
Xof the window is reached.
XThe default is
X.BR false .
X.PP
XBecause of the large amount of widget nesting in
X.I xpostit ,
Xthe following constructions are recommended for setting resources on
Xthe various widgets:
X.in 8
X.sp
X.nf
X*XPostit.\fIresource\fP
X
X*XPostit.plaid*\fIresource\fP
X
X*XPostit.Confirm*\fIresource\fP
X*XPostit.Confirm*confirm*\fIresource\fP
X*XPostit.Confirm*cancel*\fIresource\fP
X
X*XPostit.Menu*\fIresource\fP
X
X*XPostit.PostItNote*\fIresource\fP
X*XPostit.PostItNote*save*\fIresource\fP
X*XPostit.PostItNote*erase*\fIresource\fP
X*XPostit.PostItNote*destroy*\fIresource\fP
X*XPostit.PostItNote*text*\fIresource\fP
X.in 0
X.sp
X.fi
X.SH "THE CONTROL WINDOW"
X.PP
X.I Xpostit
Xallows three operations to be performed from its control window.
XPressing the left mouse button in the control window will cause all Post-it
Xnotes on the screen to be raised to the top.
XPressing the middle mouse button in the control window will cause all Post-it
Xnotes on the screen to be lowered to the bottom.
XPressing the right mouse button in the control window raises the
X.I xpostit
Xmenu.
X.SH "THE MENU"
X.PP
XThe
X.I xpostit
Xmenu provides the following selections:
X.TP 8
X.B "Create 1.5x2 Note"
XCreate a new Post-it note,
X1.5 inches tall by 2 inches wide.
XThe window will normally need to be positioned using the window manager.
X.TP 8
X.B "Create 3x3 Note"
XCreate a new Post-it note,
X3 inches square.
X.TP 8
X.B "Create 3x5 Note"
XCreate a new Post-it note,
X3 inches tall by 5 inches wide.
X.TP 8
X.B "Raise All Notes"
XRaise all Post-it notes to the top.
XThis is equivalent to pressing the left mouse button in the control window.
X.TP 8
X.B "Lower All Notes"
XLower all Post-it notes to the bottom.
XThis is equivalent to pressing the middle mouse button in the control window.
X.TP 8
X.B "Save All Notes"
XSave all Post-it notes to disk files in the save directory.
X.TP 8
X.B Exit
XExit
X.I xpostit .
XIf the
X.B \-sv
Xcommand line option was given,
Xor the
X.B saveNotes
Xresource is
X.B true ,
Xall Post-it notes will be saved to disk first.
X.PP
XTo select an item from the menu,
Xmove the mouse cursor to that item and press the left mouse button.
XIf the mouse cursor exits the menu window,
Xthe menu will be lowered automatically.
X.SH "THE POST-IT NOTE"
X.PP
XEach Post-it note is made up of four parts (plus an optional scroll bar):
Xa text window where the text of the note is stored,
Xand three buttons labeled ``save'',
X``erase'',
Xand ``destroy''.
X.PP
XTo enter text into a Post-it note,
Xsimply move the mouse cursor into the text window and start typing.
XSince the text window is actually a Text widget,
Xall the Text widget translations are accepted.
XEssentially,
Xthis means you can use most of the \s-1EMACS\s0 control keys in the window.
XAdditionally,
Xthe various mouse buttons used for manipulating the selections and cut
Xbuffer are understood.
X.PP
XAfter entering text in the Post-it note,
Xyou may wish to save the note in a disk file.
XThis way,
Xif the machine goes down,
Xor if you exit
X.IR xpostit ,
Xthe Post-it note can be restored when you restart
X.IR xpostit .
XTo save the note to a disk file,
Xmove the mouse cursor to the button labeled ``save'' and press the left
Xmouse button.
XThe note will be saved as the file ``note\fIn\fP'' in your save directory,
Xwhere
X.I n
Xis some sequence number.
X.BR \s-1NOTE\s0 :
Xit is important to remember that until you have pressed the ``save'' button,
Xthe data stored in the Post-it note is not saved on disk and can be lost if
Xthe system goes down or
X.I xpostit
Xexits.
X.PP
XTo erase the entire contents of the text window,
Xyou can press the left mouse button in the ``erase'' button.
XThis will bring up a confirmation window,
Xwhich has two buttons labeled ``confirm'' and ``cancel''.
XIf you press the ``confirm'' button,
Xthe text will be erased.
XIf you press the ``cancel'' button,
Xthe operation is canceled,
Xand nothing will happen.
X.BR \s-1NOTE\s0 :
Xerasing the text in the window does not affect any contents of the note
Xyou have saved on disk unless you press the ``save'' button again.
X.PP
XTo destroy a Post-it note,
Xgetting rid of its window on the screen and the disk file it is saved in,
Xmove the mouse cursor to the ``destroy'' button and press the left mouse
Xbutton.
XThis will bring up a confirmation window as described above.
XIf you confirm the operation,
Xthe Post-it note will disappear from the screen and the disk file it was
Xsaved in will be deleted.
X.SH "SEE ALSO"
XX(1)
X.SH BUGS
X.PP
XThe sizes of the Post-it notes are only as acurrate as the display
Xdimension and resolution returned by the server.
XOn the Sun server and possibly others,
Xthis means they aren't all that accurate.
X.PP
XWithout a color display for canary yellow notes and red plaid,
Xthe aesthetic value of
X.I xpostit
Xcannot be fully appreciated.
X.SH AUTHOR
XDavid A. Curry, Research Institute for Advanced Computer Science
X.sp
X``Post-it'' and the plaid design are registered trademarks of 3M.
END_OF_FILE
if test 8327 -ne `wc -c <'xpostit.man'`; then
    echo shar: \"'xpostit.man'\" unpacked with wrong size!
fi
# end of 'xpostit.man'
fi
echo shar: End of archive 1 \(of 2\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked both archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330
Moderator of comp.sources.x