v08i104: Xpeg, Part02/02
Ken Nelson
ssdken at watson.claremont.edu
Tue Aug 28 18:00:57 AEST 1990
Submitted-by: Ken Nelson <ssdken at watson.claremont.edu>
Posting-number: Volume 8, Issue 104
Archive-name: xpeg/part02
#! /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 2 (of 2)."
# Contents: xpeg1.0/pegbd.c xpeg1.0/xui.c
# Wrapped by ssdken at watson on Fri Aug 24 10:13:38 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'xpeg1.0/pegbd.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xpeg1.0/pegbd.c'\"
else
echo shar: Extracting \"'xpeg1.0/pegbd.c'\" \(12816 characters\)
sed "s/^X//" >'xpeg1.0/pegbd.c' <<'END_OF_FILE'
X/*************************************************************************\
X* Xpeg 1.0 *
X* *
X* Copyright 1990, Kenneth C. Nelson *
X* *
X* Rights : I, Ken Nelson own Xpeg. I am donating the source *
X* to the public domain with the restriction that nobody *
X* sells it, or anything derived from it, for anything more *
X* than media costs. Xpeg uses a dynamic object library *
X* that I don't own. See the subdirectory dynobj for *
X* restrictions on its use. *
X* *
X* Please feel free to modify Xpeg. See Todo for details. *
X* *
X\*************************************************************************/
X
X/*
X * pegbd.c - routines to update the internal storage of the pegboard.
X * This is done with a Dynamic object, storing a list of
X * person records. A person record has a name, a date last updated,
X * and a location. Each of these fields also has an X Widget associated
X * with it.
X */
X
X
X#include <stdio.h>
X
X#include "pegbd.h"
X#include "dyn.h"
X
X
X
X#define VALID_XPEG_STR "XPEG_FILE\n"
X#define UNKNOWN_STR "Unknown"
X
X
X
X/*
X * Routine which removes leading and trailing characters in string1
from string2 and
X * returns copy of the trim string.
X *
X */
X
Xextern char *strtrim();
X
X
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X
Xextern char *strdup();
X
X
Xstatic char *group = NULL; /* The name of the group this pegboard tracks. */
Xstatic char *pegfilename = NULL; /* The name of the pegfile */
Xstatic char *username = NULL; /* The name of the user running Xpeg. */
X
X
X
X/*
X * dateString() - takes a number representing time and converts to string
X * that represents the date as the Xpeg user wants it.
X * TBD - for now the
X *
X */
X
Xchar *dateString(time)
X long time;
X{
X return strdup(ctime(&time));
X}
X
X
X
X/*
X * setUserName() - sets the name of the pegfile, used by update, save,
and load.
X *
X*/
Xvoid setUserName(name)
X{
X if (name != NULL)
X username = strdup(name);
X}
X
X
X/*
X * userName() - returns the name of the person running Xpeg.
X *
X */
X
Xchar *userName()
X{
X if (username == NULL)
X return UNKNOWN_STR;
X else
X return username;
X}
X
X
X
X/*
X * personEditable() - returns TRUE if the person running this Xpeg can
edit the persons
X * location.
X */
X
Xint personEditable(personNum)
X int personNum;
X{
X int validPerson();
X Person *getPerson();
X
X if (validPerson(personNum))
X {
X return getPerson(personNum)->okay_to_edit;
X }
X else
X {
X return FALSE;
X }
X}
X
X
X
X
X/*
X * setPegfileName() - sets the name of the pegfile, used by update,
save, and load.
X *
X*/
Xvoid setPegfileName(name)
X{
X if (name != NULL)
X pegfilename = strdup(name);
X}
X
X
X/*
X * pegfileName() - returns the name of the current pegfile
X *
X */
X
Xchar *pegfileName()
X{
X return pegfilename;
X}
X
X
X
X
X/*
X * setGroupName() - sets the name of the group this pegboard tracks.
X *
X */
X
Xvoid setGroupName(name)
X char *name;
X{
X if (group != NULL)
X {
X free(NULL);
X }
X group = strdup(name);
X}
X
X
X/*
X * groupName() - returns the name of the group or empty string if not set
X *
X */
X
Xchar *groupName()
X{
X if (group == NULL)
X {
X return "";
X }
X else
X {
X return group;
X }
X}
X
X
X
X/*
X * A dynamic array of people that is in the pegboard.
X *
X */
X
X
Xstatic DynObject people = (DynObject) NULL;
X
X
X
X
X/*
X * newPerson() - allocates a new person, this is a local routine.
X *
X */
X
Xstatic Person *newPerson(name,date,location,okay_to_edit)
X char *name;
X char *date;
X char *location;
X int okay_to_edit;
X
X{
X Person *new_person;
X char tmp[256];
X
X new_person = (Person *) calloc(1,sizeof(Person));
X
X /*
X * Trim carriage returns, and update the Person record.
X *
X */
X
X new_person->name = strtrim(name,"\n");
X new_person->date = strtrim(date,"\n");
X new_person->location = strtrim(location,"\n");
X new_person->wname = NULL;
X new_person->wdate = NULL;
X new_person->wlocation = NULL;
X new_person->okay_to_edit = okay_to_edit;
X
X return new_person;
X}
X
X
X
X
X/*
X * getPerson() - returns the numbered person record.
X * this is a local routine.
X *
X */
X
Xstatic Person *getPerson(number)
X int number;
X{
X return (Person *) DynGet(people,number);
X}
X
X
X
X
X/*
X * firstPerson() - returns the number of the first person in the pegboard.
X *
X */
X
Xint firstPerson()
X{
X if (people != NULL)
X return DynLow(people);
X else
X return 0;
X}
X
X
X
X
X/*
X * lastPerson() - returns the number of the last person in the pegboard.
X *
X */
X
Xint lastPerson()
X{
X if (people != NULL)
X {
X return DynHigh(people);
X }
X else
X {
X return 0;
X }
X}
X
X
X
X/*
X * numPeople() - returns the number of people in the pegboard.
X *
X */
X
Xint numPeople()
X{
X if (people != NULL)
X return DynSize(people);
X else
X return 0;
X}
X
X
X
X/*
X * nextPerson() - returns the number of the next person in the pegboard.
X * kind of a kludge in that it only increments a number,
X * but it reads nicer than i++.
X */
X
Xint nextPerson(personNum)
X{
X return personNum+1;
X}
X
X
X
X/*
X * validPerson() - returns TRUE if personNum identifies a valid person,
FALSE otherwise.
X *
X */
X
Xstatic int validPerson(personNum)
X{
X return (personNum >= firstPerson() && personNum <= lastPerson());
X}
X
X
X
X
X
X/*
X * setPersonName() - sets the name of the numbered person, does nothing if
X * the person number is not valid.
X *
X */
X
Xvoid setPersonName(personNum,name)
X int personNum;
X char *name;
X{
X Person *person;
X
X if (validPerson(personNum))
X {
X person = getPerson(personNum);
X if (person->name != NULL)
X {
X cfree(person->name);
X }
X person->name = strtrim(name,"\n"); /* add name without leading of
trailing \n's */
X }
X}
X
X
X/*
X * setPersonNameWidget() - sets the name widget of the numbered person,
does nothing if
X * the person number is not valid.
X *
X */
X
Xvoid setPersonNameWidget(personNum,w)
X int personNum;
X Widget w;
X{
X Person *person;
X
X if (validPerson(personNum))
X {
X person = getPerson(personNum);
X person->wname = w;
X }
X}
X
X
X
X/*
X * personName() - returns the name of the numbered person, or Unknown string.
X *
X */
X
X
Xchar *personName(personNum)
X int personNum;
X{
X
X if (validPerson(personNum))
X {
X return getPerson(personNum)->name;
X }
X else
X {
X return UNKNOWN_STR;
X }
X}
X
X
X
X/*
X * personNameWidget() - returns the name of the numbered person, or NULL.
X *
X */
X
X
XWidget personNameWidget(personNum)
X int personNum;
X{
X
X if (validPerson(personNum))
X {
X return getPerson(personNum)->wname;
X }
X else
X {
X return NULL;
X }
X}
X
X
X
X
X/*
X * personDate() - returns the date that this person was last updated into
X * the pegboard, or uknown string.
X *
X */
X
X
Xchar *personDate(personNum)
X int personNum;
X{
X
X if (validPerson(personNum))
X {
X return getPerson(personNum)->date;
X }
X else
X {
X return UNKNOWN_STR;
X }
X}
X
X
X
X/*
X * personDateWidget() - returns the date widget of the numbered person,
or NULL.
X *
X */
X
X
XWidget personDateWidget(personNum)
X int personNum;
X{
X
X if (validPerson(personNum))
X {
X return getPerson(personNum)->wdate;
X }
X else
X {
X return NULL;
X }
X}
X
X
X
X/*
X * setPersonDate() - sets the date of the numbered person, does nothing if
X * the person number is not valid.
X *
X */
X
Xvoid setPersonDate(personNum,date)
X int personNum;
X char *date;
X{
X Person *person;
X
X if (validPerson(personNum))
X {
X person = getPerson(personNum);
X if (person->date != NULL)
X {
X cfree(person->date);
X }
X person->date = strtrim(date,"\n"); /* add name without leading of
trailing \n's */
X }
X}
X
X
X
X/*
X * setPersonDateWidget() - sets the date widget of the numbered person,
does nothing if
X * the person number is not valid.
X *
X */
X
Xvoid setPersonDateWidget(personNum,w)
X int personNum;
X Widget w;
X{
X Person *person;
X
X if (validPerson(personNum))
X {
X person = getPerson(personNum);
X person->wdate = w;
X }
X}
X
X
X
X
X
X/*
X * personLocation() - returns the location of this person, or the
unknown string.
X *
X */
X
X
Xchar *personLocation(personNum)
X int personNum;
X{
X
X if (validPerson(personNum))
X {
X return getPerson(personNum)->location;
X }
X else
X {
X return UNKNOWN_STR;
X }
X}
X
X
X
X/*
X * personLocationWidget() - returns the location of the numbered
person, or NULL.
X *
X */
X
X
XWidget personLocationWidget(personNum)
X int personNum;
X{
X
X if (validPerson(personNum))
X {
X return getPerson(personNum)->wlocation;
X }
X else
X {
X return NULL;
X }
X}
X
X
X
X
X/*
X * setPersonLocation() - sets the location of the numbered person, does
nothing if
X * the person number is not valid.
X *
X */
X
Xvoid setPersonLocation(personNum,loc)
X int personNum;
X char *loc;
X{
X Person *person;
X
X if (validPerson(personNum))
X {
X person = getPerson(personNum);
X if (person->location != NULL)
X {
X cfree(person->location);
X }
X person->location = strtrim(loc,"\n"); /* add loc without leading of
trailing \n's */
X }
X}
X
X
X/*
X * setPersonLocationWidget() - sets the location widget of the numbered
person, does nothing if
X * the person number is not valid.
X *
X */
X
Xvoid setPersonLocationWidget(personNum,w)
X int personNum;
X Widget w;
X{
X Person *person;
X
X if (validPerson(personNum))
X {
X person = getPerson(personNum);
X person->wlocation = w;
X }
X}
X
X
X
X
X
X
X/*
X * addPerson() - adds the person into the pegboard, no checking to see if the
X * name of the person matches one already there,etc...
X */
X
Xvoid addPerson(name,date,location,changeable)
X char *name;
X char *date;
X char *location;
X int changeable;
X{
X Person new_person;
X
X if (people == NULL)
X {
X /*
X * Create a dynmaic array realloced every 100 inserts
X *
X */
X
X people = DynCreate(sizeof(Person),100);
X }
X DynAdd(people,newPerson(name,date,location,changeable));
X}
X
X
X
X
X/*
X * buildXpegBoard() - reads the Xpeg file and builds up the board.
X *
X*/
X
X
Xvoid buildXpegBoard(filename)
X char *filename;
X{
X FILE *file = NULL;
X char line[256];
X char name[256],date[256],location[256];
X int okay_to_edit = FALSE;
X
X
X file = fopen(filename,"r");
X if (file == NULL)
X {
X printf("xpeg: Could not open %s.\n",filename);
X }
X else
X {
X fgets(line,256,file);
X if (strcmp(line,VALID_XPEG_STR) != 0)
X {
X printf("xpeg: Invalid Xpeg file: %s\n",filename);
X exit(1);
X }
X else
X {
X fgets(line,256,file);
X setGroupName(line);
X
X while (!feof(file))
X {
X fgets(name,256,file);
X
X if (strcmp(userName(),strtrim(name,"\n")) == 0)
X {
X okay_to_edit = TRUE;
X }
X else
X {
X okay_to_edit = FALSE;
X }
X
X fgets(date,256,file);
X fgets(location,256,file);
X if (!feof(file))
X {
X addPerson(name,date,location,okay_to_edit);
X }
X }
X fclose(file);
X }
X }
X
X}
X
X
X
X
X/*
X * updateXpegBoard() - re-reads the file and updates any date and location
X * information that has changed.
X *
X */
X
Xvoid updateXpegBoard(filename)
X char *filename;
X{
X FILE *file = NULL;
X char line[256];
X char name[256],date[256],location[256];
X int personNum;
X int num_people;
X
X num_people = numPeople(people);
X
X file = fopen(filename,"r");
X if (file == NULL)
X {
X printf("Xpeg: Could not open %s.\n",filename);
X }
X else
X {
X fgets(line,256,file);
X if (strcmp(line,VALID_XPEG_STR) != 0)
X {
X printf("Xpeg: Invalid Xpeg file: %s\n",filename);
X exit(1);
X }
X else
X {
X fgets(line,256,file);
X setGroupName(line);
X
X personNum = firstPerson();
X while (!feof(file))
X {
X fgets(name,256,file);
X fgets(date,256,file);
X fgets(location,256,file);
X
X /*
X * If more people have been added then add them.
X * else just update their information.
X *
X */
X
X if (!feof(file))
X {
X if (personNum > num_people)
X {
X addPerson(name,date,location,FALSE);
X }
X else
X {
X setPersonName(personNum,strtrim(name,"\n"));
X setPersonDate(personNum,strtrim(date,"\n"));
X setPersonLocation(personNum,strtrim(location,"\n"));
X }
X personNum = nextPerson(personNum);
X }
X }
X fclose(file);
X }
X }
X
X}
X
X
X
X
X
X/*
X * saveXpegBoard() - saves the current board into the xpeg file.
X *
X */
X
Xvoid saveXpegBoard(filename)
X char *filename;
X{
X FILE *file = NULL;
X int personNum;
X char *groupName();
X char *strtrim();
X
X file = fopen(filename,"w");
X if (file != NULL)
X {
X fprintf(file,"%s",VALID_XPEG_STR);
X fprintf(file,"%s\n",strtrim(groupName(),"\n"));
X if (numPeople() > 0)
X {
X for (personNum = firstPerson(); personNum <= lastPerson();
personNum = nextPerson(personNum))
X {
X fprintf(file,"%s\n%s\n%s\n",personName(personNum),
X personDate(personNum),
X personLocation(personNum)
X );
X }
X }
X fclose(file);
X }
X else
X {
X printf("Xpeg: Error saving pegboard file: %s\n",filename);
X }
X}
X
X
X
END_OF_FILE
if test 12816 -ne `wc -c <'xpeg1.0/pegbd.c'`; then
echo shar: \"'xpeg1.0/pegbd.c'\" unpacked with wrong size!
fi
# end of 'xpeg1.0/pegbd.c'
fi
if test -f 'xpeg1.0/xui.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xpeg1.0/xui.c'\"
else
echo shar: Extracting \"'xpeg1.0/xui.c'\" \(21089 characters\)
sed "s/^X//" >'xpeg1.0/xui.c' <<'END_OF_FILE'
X/*************************************************************************\
X* Xpeg 1.0 *
X* *
X* Copyright 1990, Kenneth C. Nelson *
X* *
X* Rights : I, Ken Nelson own Xpeg. I am donating the source *
X* to the public domain with the restriction that nobody *
X* sells it, or anything derived from it, for anything more *
X* than media costs. Xpeg uses a dynamic object library *
X* that I don't own. See the subdirectory dynobj for *
X* restrictions on its use. *
X* *
X* Please feel free to modify Xpeg. See Todo for details. *
X* *
X\*************************************************************************/
X
X/*
X * xui.c - builds the X interface to Xpeg.
X *
X */
X
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/Xaw/Box.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xaw/Command.h>
X#include <X11/Xaw/Paned.h>
X#include <X11/Xaw/AsciiText.h>
X#include <X11/Xaw/Dialog.h>
X#include <X11/Shell.h>
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/Viewport.h>
X
X#include "pegbd.h"
X
X
X#include "xpeg.icon"
X
X
X#define DEFAULT_HELP "XPeg, a tool for the 90's."
X#define ABOUT_HELP "About Xpeg."
X#define QUIT_HELP "Quit Xpeg, no confirmation."
X#define SAVE_HELP "Save any changes in the pegboard."
X#define UPDATE_HELP "Rescan status of people in the pegboard."
X#define NEW_HELP "Add a new person to the pegboard."
X#define GROUP_HELP "Change, or edit the name of the group this
pegboard tracks."
X
X
X#define ABOUT_STR \
X" Xpeg 1.0\n\
X By\n\
X Ken Nelson\n\n\
X Send me an email if use Xpeg.\n\
X ssdken at jarthur.claremont.edu\n\n\
X Enjoy!!\n\
X"
X
X#define NAME_WIDTH 150
X#define DATE_WIDTH 140
X#define LOC_WIDTH 300
X#define XPEG_WIDTH 690
X
X/*
X * Widgets that need (or it is nice) to have global.
X *
X */
X
XWidget titleBar;
XWidget groupBar;
XWidget toplevel;
XWidget helpArea;
XWidget buttonBox;
XWidget viewport;
XWidget commandPane;
XWidget groupDialogShell;
XWidget newPersonFormShell;
XWidget nameEditor;
XWidget locEditor;
XWidget groupEditor;
XWidget aboutDialogShell;
X
X#include <stdio.h>
X
X
X
X/*
X * Action Routines
X *
X */
X
X
X/*ARGSUSED*/
Xvoid ACTsetHelp(w,event)
X Widget w;
X XButtonEvent event;
X{
X char *widgetLabel;
X
X XtVaGetValues(w,"label",&widgetLabel,NULL);
X
X if (strcmp(widgetLabel,"quit") == 0)
X {
X XtVaSetValues(helpArea,XtNlabel,QUIT_HELP,NULL);
X }
X else
X if (strcmp(widgetLabel,"save") == 0)
X {
X XtVaSetValues(helpArea,XtNlabel,SAVE_HELP,NULL);
X }
X else
X if (strcmp(widgetLabel,"update") == 0)
X {
X XtVaSetValues(helpArea,XtNlabel,UPDATE_HELP,NULL);
X }
X else
X if (strcmp(widgetLabel,"new") == 0)
X {
X XtVaSetValues(helpArea,XtNlabel,NEW_HELP,NULL);
X }
X else
X if (strcmp(widgetLabel,"group") == 0)
X {
X XtVaSetValues(helpArea,XtNlabel,GROUP_HELP,NULL);
X }
X else
X if (strcmp(widgetLabel,"about") == 0)
X {
X XtVaSetValues(helpArea,XtNlabel,ABOUT_HELP,NULL);
X }
X else
X {
X XtVaSetValues(helpArea,XtNlabel,DEFAULT_HELP,NULL);
X }
X
X}
X
X
X/*ARGSUSED*/
Xvoid ACTresetHelp(w,event)
X Widget w;
X XButtonEvent event;
X{
X XtVaSetValues(helpArea,XtNlabel,DEFAULT_HELP,NULL);
X}
X
X
X
X
X/*
X * Call Back Routines
X *
X */
X
X/*
X * Callback for About button
X *
X */
X
X
X/*ARGSUSED*/
Xvoid CBabout(w,client_data,call_data)
X Widget w;
X XtPointer client_data;
X XtPointer call_data;
X{
X Position x,y;
X Dimension width,height;
X
X /*
X * Locate where the invoking widget is.
X * So we can place the popup in the middle.
X *
X */
X
X XtVaGetValues(w,"width",&width,"height",&height,NULL);
X XtTranslateCoords(toplevel,
X (Position) width/2, /* X */
X (Position) height/2, /* Y */
X &x,&y
X );
X
X XtVaSetValues(aboutDialogShell,
X XtNx,x,
X XtNy,y,
X NULL
X );
X
X XtPopup(aboutDialogShell,XtGrabNonexclusive);
X}
X
X
X/*
X * CBaboutDismiss() - callback for the dismiss button of the about popup.
X *
X */
X
X/*ARGUSED*/
Xvoid CBaboutDismiss(w,client_data,call_data)
X Widget w;
X XtPointer client_data;
X XtPointer call_data;
X{
X XtPopdown(aboutDialogShell);
X}
X
X
X
X/*
X * Callback for the Quit Button
X *
X */
X
X/*ARGSUSED*/
Xvoid CBquit(w,client_data,call_data)
X Widget w;
X XtPointer client_data;
X XtPointer call_data;
X{
X exit(0);
X}
X
X
X/*
X * CBupdate() - Callback for update button.
X *
X */
X
X/*ARGSUSED*/
Xvoid CBupdate(w,client_data,call_data)
X Widget w;
X XtPointer client_data;
X XtPointer call_data;
X{
X int personNum;
X void addXpegPerson();
X void setGroupBar();
X
X /*
X * Use updateXpegBoard to read in the file
X *
X */
X
X updateXpegBoard(pegfileName());
X
X /*
X * Now take the info read in and update what the
X * user sees.
X *
X */
X
X setGroupBar(groupName());
X if (numPeople() > 0)
X {
X for (personNum=firstPerson(); personNum<=lastPerson();
personNum=nextPerson(personNum))
X {
X /*
X * If there is a widget for this person then update it, else
X * this is a new person and the X pegboard needs to be updated
X *
X */
X
X if (personNameWidget(personNum) != NULL)
X {
X XtVaSetValues(personNameWidget(personNum),
X XtNlabel,personName(personNum),
X XtNwidth,NAME_WIDTH,
X NULL
X );
X XtVaSetValues(personDateWidget(personNum),
X XtNlabel,personDate(personNum),
X XtNwidth,DATE_WIDTH,
X NULL
X );
X XtVaSetValues(personLocationWidget(personNum),
X XtNstring,personLocation(personNum),
X XtNwidth,LOC_WIDTH,
X NULL
X );
X
X }
X else
X {
X addXpegPerson(personNum,
X personName(personNum),
X personDate(personNum),
X personLocation(personNum)
X );
X }
X }
X }
X
X}
X
X
X
X/*
X * CBsave() - callback for the save button.
X *
X */
X
X
X/*ARGSUSED*/
Xvoid CBsave(w,client_data,call_data)
X Widget w;
X XtPointer client_data;
X XtPointer call_data;
X{
X int personNum;
X char *location;
X char *date;
X
X /*
X * update the strings in the person record, from the
X * text editors.
X *
X */
X
X if (numPeople() > 0)
X {
X for (personNum=firstPerson(); personNum<=lastPerson();
personNum=nextPerson(personNum))
X {
X if (personLocationWidget(personNum) != NULL)
X {
X XtVaGetValues(personLocationWidget(personNum),
X "string",&location,
X NULL
X );
X
X /*
X * if the location has changed update the time stamp in the pegboard and
X * on the screen. Also update the new location in the pegfile.
X */
X
X if (strcmp(location,personLocation(personNum)) != 0)
X {
X date = dateString(time(0));
X
X XtVaSetValues(personDateWidget(personNum),
X XtNlabel,date,
X XtNwidth,DATE_WIDTH,
X NULL
X );
X
X setPersonDate(personNum,date);
X setPersonLocation(personNum,location);
X }
X }
X }
X }
X
X saveXpegBoard(pegfileName());
X
X}
X
X
X/*
X * CBnew() - callback for the new button.
X * Pops up the new person form.
X *
X */
X
X
X/*ARGSUSED*/
Xvoid CBnew(w,client_data,call_data)
X Widget w;
X XtPointer client_data;
X XtPointer call_data;
X{
X
X Position x,y;
X Dimension width,height;
X
X /*
X * Locate where the invoking widget is.
X * So we can place the popup in the middle.
X *
X */
X
X XtVaGetValues(w,"width",&width,"height",&height,NULL);
X XtTranslateCoords(toplevel,
X (Position) width/2, /* X */
X (Position) height/2, /* Y */
X &x,&y
X );
X
X XtVaSetValues(newPersonFormShell,
X XtNx,x,
X XtNy,y,
X NULL
X );
X
X XtPopup(newPersonFormShell,XtGrabNonexclusive);
X
X}
X
X
X
X/*
X * CBgroup() - callback for the group button.
X *
X */
X
X
X/*ARGSUSED*/
Xvoid CBgroup(w,client_data,call_data)
X Widget w;
X XtPointer client_data;
X XtPointer call_data;
X{
X Position x,y;
X Dimension width,height;
X
X XtVaGetValues(w,"width",&width,"height",&height,NULL);
X XtTranslateCoords(toplevel,
X (Position) width/2, /* X */
X (Position) height/2, /* Y */
X &x,&y
X );
X
X XtVaSetValues(groupDialogShell,
X XtNx,x,
X XtNy,y,
X NULL
X );
X
X
X XtPopup(groupDialogShell,XtGrabNonexclusive);
X}
X
X
X/*
X * CBgroupOk() - callback for the change group dialog OK button.
X *
X */
X
X
X/*ARGSUSED*/
Xvoid CBgroupOk(w,dialog,call_data)
X Widget w;
X Widget dialog; /* The dialog this button was in. */
X XtPointer call_data;
X{
X char *group;
X void setGroupBar();
X
X XtVaGetValues(groupEditor,"string",&group);
X setGroupBar(group);
X
X /*
X * Set the group name to the one in the title bar
X */
X
X setGroupName(group);
X
X XtPopdown(groupDialogShell);
X
X}
X
X
X/*
X * CBnewPersonAdd() - callback for the change group dialog OK button.
X *
X */
X
X
X/*ARGSUSED*/
Xvoid CBnewPersonAdd(w,client_data,call_data)
X Widget w;
X XtPointer client_data;
X XtPointer call_data;
X{
X char *name,*location;
X void addXpegPerson();
X char *date;
X
X XtPopdown(newPersonFormShell);
X
X XtVaGetValues(nameEditor,"string",&name);
X XtVaGetValues(locEditor,"string",&location);
X date = dateString(time(0));
X addPerson(name,date,location,TRUE);
X addXpegPerson(lastPerson(),name,date,location);
X}
X
X
X
X
X/*
X * CBnewPersonCancel() - callback for the add new person cancel button.
X *
X */
X
X
X/*ARGSUSED*/
Xvoid CBnewPersonCancel(w,dialog,call_data)
X Widget w;
X Widget dialog; /* The dialog this button was in. */
X XtPointer call_data;
X{
X XtPopdown(newPersonFormShell);
X}
X
X
Xvoid setTitleBar(title)
X char *title;
X{
X XtVaSetValues(titleBar,XtNlabel,title,NULL);
X}
X
X
XWidget addTitleBar(parent,title)
X Widget parent;
X char *title;
X{
X return XtVaCreateManagedWidget(
X "titlebar",
X labelWidgetClass,
X parent,
X XtNlabel,title,
X NULL
X );
X}
X
X
XWidget addGroupBar(parent,group)
X Widget parent;
X char *group;
X{
X return XtVaCreateManagedWidget(
X "groupbar",
X labelWidgetClass,
X parent,
X XtNlabel,group,
X NULL
X );
X}
X
Xvoid setGroupBar(group)
X char *group;
X{
X XtVaSetValues(groupBar,XtNlabel,group,NULL);
X}
X
X
X
Xchar *groupBarStr()
X{
X char *group;
X
X XtVaGetValues(groupBar,"string",&group,NULL);
X return group;
X
X}
X
X
X/*
X * buildGroupDialog() - Builds the group dialog and returns the shell
that holds it.
X *
X */
X
XWidget buildGroupDialog(parent)
X Widget parent;
X{
X Widget popupShell;
X Widget dialog,button,label;
X
X
X popupShell = XtCreatePopupShell(
X "groupShell",
X transientShellWidgetClass,
X parent,
X NULL,
X 0
X );
X
X dialog = XtVaCreateManagedWidget(
X "groupDialog",
X formWidgetClass,
X popupShell,
X NULL
X );
X
X
X label = XtVaCreateManagedWidget(
X "groupDialogLabel",
X labelWidgetClass,
X dialog,
X XtNborderWidth,0,
X XtNlabel,"Group Description: ",
X NULL
X );
X
X groupEditor = XtVaCreateManagedWidget(
X "groupEditor",
X asciiTextWidgetClass,
X dialog,
X XtNfromHoriz,label,
X XtNstring,groupName(),
X XtNwidth,400,
X XtNeditType,XawtextEdit,
X NULL
X );
X
X
X button = XtVaCreateManagedWidget(
X "groupDialogButton",
X commandWidgetClass,
X dialog,
X XtNlabel,"OK",
X XtNfromVert,label,
X NULL
X );
X
X XtAddCallback(button,XtNcallback,CBgroupOk,dialog);
X return popupShell;
X}
X
X
X
X
X/*
X * buildAboutDialog() - Builds the about dialog and returns the shell
that holds it.
X *
X */
X
XWidget buildAboutDialog(parent)
X Widget parent;
X{
X Widget popupShell;
X Widget dialog,button,label;
X
X
X popupShell = XtCreatePopupShell(
X "About",
X transientShellWidgetClass,
X parent,
X NULL,
X 0
X );
X
X dialog = XtVaCreateManagedWidget(
X "aboutForm",
X formWidgetClass,
X popupShell,
X NULL
X );
X
X
X label = XtVaCreateManagedWidget(
X "groupDialogLabel",
X labelWidgetClass,
X dialog,
X XtNborderWidth,0,
X XtNjustify,XtJustifyCenter,
X XtNlabel,ABOUT_STR,
X NULL
X );
X
X
X button = XtVaCreateManagedWidget(
X "aboutDismissButton",
X commandWidgetClass,
X dialog,
X XtNlabel,"Dismiss",
X XtNfromVert,label,
X NULL
X );
X
X XtAddCallback(button,XtNcallback,CBaboutDismiss,dialog);
X
X return popupShell;
X}
X
X
X
XWidget buildNewPersonForm(parent)
X Widget parent;
X{
X
X Widget popupShell;
X Widget form;
X Widget addButton,cancelButton;
X Widget nameLabel,locLabel;
X
X
X popupShell = XtCreatePopupShell(
X "NewPerson",
X transientShellWidgetClass,
X parent,
X NULL,
X 0
X );
X
X form = XtVaCreateManagedWidget(
X "newPersonForm",
X formWidgetClass,
X popupShell,
X NULL
X );
X
X nameLabel = XtVaCreateManagedWidget(
X "newPersonLabel",
X labelWidgetClass,
X form,
X XtNlabel,"Name :",
X XtNborderWidth,0,
X NULL
X );
X
X nameEditor = XtVaCreateManagedWidget(
X "nameEditor",
X asciiTextWidgetClass,
X form,
X XtNwidth,300,
X XtNeditType,XawtextEdit,
X XtNfromHoriz,nameLabel,
X NULL
X );
X
X locLabel = XtVaCreateManagedWidget(
X "newPersonLabel",
X labelWidgetClass,
X form,
X XtNlabel,"Enter Location: ",
X XtNfromVert,nameLabel,
X XtNborderWidth,0,
X NULL
X );
X
X
X locEditor = XtVaCreateManagedWidget(
X "locationEditor",
X asciiTextWidgetClass,
X form,
X XtNwidth,300,
X XtNeditType,XawtextEdit,
X XtNfromVert,nameEditor,
X XtNfromHoriz,locLabel,
X NULL
X );
X
X
X
X cancelButton = XtVaCreateManagedWidget(
X "newPersonCancel",
X commandWidgetClass,
X form,
X XtNlabel,"cancel",
X XtNfromVert,locLabel,
X NULL
X );
X
X
X XtAddCallback(
X cancelButton,
X XtNcallback,
X CBnewPersonCancel,
X NULL
X );
X
X
X addButton = XtVaCreateManagedWidget(
X "newPersonAdd",
X commandWidgetClass,
X form,
X XtNlabel,"Add",
X XtNfromHoriz,cancelButton,
X XtNfromVert,locLabel,
X NULL
X );
X XtAddCallback(
X addButton,
X XtNcallback,
X CBnewPersonAdd,
X NULL
X );
X
X
X return popupShell;
X
X}
X
X
X
XWidget addXpegButtonArea(parent)
X Widget parent;
X {
X Widget buttonbox;
X Widget button,label;
X XtTranslations buttonTranslations;
X
X
X /*
X * Append to the translation table for thse buttons so
X * that help is updated on entry and exit.
X *
X */
X
X static char buttonTranslationsStr[] = "#override\n\
X <EnterWindow> : highlight() sethelp() \n\
X <LeaveWindow> : reset() resethelp() ";
X
X /*
X * These are the actions that update the help based on widget label,
X * and reset the help to the default help.
X *
X */
X
X static XtActionsRec buttonActions[] = {
X {"sethelp",ACTsetHelp},
X {"resethelp",ACTresetHelp}
X };
X
X
X buttonTranslations = XtParseTranslationTable(buttonTranslationsStr);
X
X
X /*
X * Setup the actions that provide the help when entering a window.
X *
X */
X
X
X XtAddActions(buttonActions,XtNumber(buttonActions));
X
X
X /*
X * Now create an Athena Box widget which will manage these
X * buttons.
X */
X
X buttonbox = XtVaCreateManagedWidget(
X "buttonbox",
X boxWidgetClass,
X parent,
X XtNwidth,200,
X XtNheight,200,
X NULL
X );
X
X /*
X * And then the buttons, which are Athena Command Widgets.
X *
X */
X
X button = XtVaCreateManagedWidget(
X "about",
X commandWidgetClass,
X buttonbox,
X XtNlabel,"about",
X NULL
X );
X
X
X XtAddCallback(button,XtNcallback,CBabout,NULL);
X XtOverrideTranslations(button,buttonTranslations);
X
X button = XtVaCreateManagedWidget(
X "quit",
X commandWidgetClass,
X buttonbox,
X XtNlabel,"quit",
X NULL
X );
X
X XtAddCallback(button,XtNcallback,CBquit,NULL);
X XtOverrideTranslations(button,buttonTranslations);
X
X
X
X button = XtVaCreateManagedWidget(
X "update",
X commandWidgetClass,
X buttonbox,
X XtNlabel,"update",
X NULL
X );
X XtAddCallback(button,XtNcallback,CBupdate,NULL);
X XtOverrideTranslations(button,buttonTranslations);
X
X
X button = XtVaCreateManagedWidget(
X "save",
X commandWidgetClass,
X buttonbox,
X XtNlabel,"save",
X NULL
X );
X XtAddCallback(button,XtNcallback,CBsave,NULL);
X XtOverrideTranslations(button,buttonTranslations);
X
X button = XtVaCreateManagedWidget(
X "new",
X commandWidgetClass,
X buttonbox,
X XtNlabel,"new",
X NULL
X );
X XtAddCallback(button,XtNcallback,CBnew,NULL);
X XtOverrideTranslations(button,buttonTranslations);
X
X
X button = XtVaCreateManagedWidget(
X "group",
X commandWidgetClass,
X buttonbox,
X XtNlabel,"group",
X NULL
X );
X XtAddCallback(button,XtNcallback,CBgroup,NULL);
X XtOverrideTranslations(button,buttonTranslations);
X
X
X label = XtVaCreateManagedWidget(
X "yourusername",
X labelWidgetClass,
X buttonbox,
X XtNlabel,"Your Username: ",
X XtNborderWidth,0,
X NULL
X );
X
X label = XtVaCreateManagedWidget(
X "username",
X labelWidgetClass,
X buttonbox,
X XtNlabel,userName(),
X XtNborderWidth,0,
X NULL
X );
X
X return buttonbox;
X}
X
X
X
Xvoid addXpegPerson(personNumber,name,date,loc)
X int personNumber;
X char *name;
X char *date;
X char *loc;
X{
X Widget box;
X Widget wname,wdate,wloc;
X char text[256];
X Person *person;
X
X
X box = XtVaCreateManagedWidget(
X tmpnam(text),
X boxWidgetClass,
X commandPane,
X NULL
X );
X
X XawPanedAllowResize(box,FALSE);
X
X wname = XtVaCreateManagedWidget(
X tmpnam(text),
X labelWidgetClass,
X box,
X XtNlabel,name,
X XtNwidth,NAME_WIDTH,
X NULL
X );
X
X wdate = XtVaCreateManagedWidget(
X tmpnam(text),
X labelWidgetClass,
X box,
X XtNlabel,date,
X XtNwidth,DATE_WIDTH,
X NULL
X );
X
X if (personEditable(personNumber))
X {
X wloc = XtVaCreateManagedWidget(
X tmpnam(text),
X asciiTextWidgetClass,
X box,
X XtNstring,loc,
X XtNwidth,LOC_WIDTH,
X XtNeditType,XawtextEdit,
X NULL
X );
X }
X else
X {
X wloc = XtVaCreateManagedWidget(
X tmpnam(text),
X asciiTextWidgetClass,
X box,
X XtNstring,loc,
X XtNwidth,LOC_WIDTH,
X XtNeditType,XawtextRead,
X NULL
X );
X }
X
X /*
X * Update this persons Widgets.
X *
X */
X
X setPersonNameWidget(personNumber,wname);
X setPersonDateWidget(personNumber,wdate);
X setPersonLocationWidget(personNumber,wloc);
X
X}
X
X
X
X
X/*
X * initXpegInterface() - parses the command line for xtoolkit options,
X * and then makes a toplevel shell.
X*/
X
Xvoid initXpegInterface(argc,argv)
X int *argc;
X char **argv;
X{
X
X
X toplevel = XtInitialize(
X argv[0],
X (char *)xpeg_version(),
X NULL,
X 0,
X argc,
X argv
X );
X
X}
X
X
X
Xvoid addXpegIcon()
X{
X Pixmap icon_pixmap;
X
X icon_pixmap = XCreateBitmapFromData(XtDisplay(toplevel),
X RootWindowOfScreen(XtScreen(toplevel)),
X xpeg_bits,
X xpeg_width,
X xpeg_height
X );
X XtVaSetValues(toplevel,XtNiconPixmap,icon_pixmap,NULL);
X}
X
X
X/*
X * buildXpegInterface() - does just that, builds the X interface.
X *
X */
X
Xvoid buildXpegInterface()
X{
X
X int personNum;
X
X
X addXpegIcon();
X
X commandPane = XtVaCreateManagedWidget("commandpane",
X panedWidgetClass,
X toplevel,
X XtNwidth,XPEG_WIDTH,
X NULL
X );
X
X titleBar = addTitleBar(commandPane,(char *)xpeg_version());
X
X groupBar = addGroupBar(commandPane,groupName());
X groupDialogShell = buildGroupDialog(toplevel);
X aboutDialogShell = buildAboutDialog(toplevel);
X newPersonFormShell = buildNewPersonForm(toplevel);
X
X
X helpArea = XtVaCreateManagedWidget(
X "help",
X labelWidgetClass,
X commandPane,
X XtNlabel,DEFAULT_HELP,
X NULL
X );
X
X
X XawPanedAllowResize(titleBar,FALSE);
X
X /*
X * Add the button command area.
X *
X */
X
X buttonBox = addXpegButtonArea(commandPane);
X XawPanedAllowResize(buttonBox,FALSE);
X
X
X /*
X * Now for each person read in from the pegboard file, add them to
X * the interface.
X *
X */
X
X
X if (numPeople() > 0)
X {
X for (personNum = firstPerson(); personNum <= lastPerson();
personNum = nextPerson(personNum))
X {
X addXpegPerson(personNum,
X personName(personNum),
X personDate(personNum),
X personLocation(personNum)
X );
X }
X }
X
X}
X
X
X
X/*
X * runXpegInterface() - realizes the toplevel x widget, and then does
the X event loop.
X *
X */
X
Xvoid runXpegInterface()
X{
X XtRealizeWidget(toplevel); /* Realize the widgets */
X XtMainLoop();
X}
X
END_OF_FILE
if test 21089 -ne `wc -c <'xpeg1.0/xui.c'`; then
echo shar: \"'xpeg1.0/xui.c'\" unpacked with wrong size!
fi
# end of 'xpeg1.0/xui.c'
fi
echo shar: End of archive 2 \(of 2\).
cp /dev/null ark2isdone
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
Keywords:
dan
----------------------------------------------------
O'Reilly && Associates argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.
More information about the Comp.sources.x
mailing list