home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-20 | 55.3 KB | 1,873 lines |
- Path: sparky!uunet!stanford.edu!morrow.stanford.edu!sep!steve
- From: steve@sep.Stanford.EDU (Steve Cole)
- Newsgroups: alt.sources
- Subject: xtpanel 2.0 - interactive program builder - part 06/10
- Followup-To: alt.sources.d
- Date: 21 Nov 1992 00:32:51 GMT
- Organization: Stanford Exploration Project
- Lines: 1860
- Distribution: world
- Message-ID: <1ek03jINN194@morrow.stanford.edu>
- NNTP-Posting-Host: taal.stanford.edu
-
-
- Submitted-by: steve@sep.Stanford.EDU
- Archive-name: xtpanel/part06
-
- #!/bin/sh
- # This is part 06 of a multipart archive
- # ============= xtpanel/button.c ==============
- if test ! -d 'xtpanel'; then
- echo 'x - creating directory xtpanel'
- mkdir 'xtpanel'
- fi
- if test -f 'xtpanel/button.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/button.c (File already exists)'
- else
- echo 'x - extracting xtpanel/button.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/button.c' &&
- /*
- X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
- X * University. Official permission to use this software is included in
- X * the documentation. It authorizes you to use this file for any
- X * non-commercial purpose, provided that this copyright notice is not
- X * removed and that any modifications made to this file are commented
- X * and dated in the style of the example below.
- X */
- X
- /*
- X *
- X * source file: ./xtpanel/button.c
- X *
- X * Steve Cole, Dave Nichols (SEP), August 28 1992
- X * Inserted this sample edit history entry.
- X * Please log any further modifications made to this file:
- X * Steve Cole, Dave Nichols (SEP), November 20 1992 - version 2.00
- X * 1) added new objects: toggle, scrollbar, graph.
- X * 2) added new actions: ASSIGN, SET.
- X * 3) objects can have multiple actions.
- X * 4) backquoted strings in actions get executed at action time.
- X */
- X
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- X
- #include <X11/Xaw/Cardinals.h>
- #include <X11/Xaw/Command.h>
- #include <X11/Xaw/Toggle.h>
- X
- #include <stdio.h>
- X
- #include "object.h"
- #include "tree.h"
- #include "builders.h"
- X
- typedef struct buttoninfo {
- X char* type;
- X char* value;
- } _binf;
- X
- void build_button(root,parent,type)
- X entry *root;
- X Widget parent;
- X char *type;
- {
- X Objdef *object;
- X char* label;
- X struct buttoninfo *button_info;
- X char defname[12];
- X Widget button;
- X Arg args[20];
- X int narg;
- X static int numbutt=1;
- X extern void button_callback();
- X extern void button_update();
- X
- X /* create new object */
- X object = new_object();
- X
- X /* construct default button name */
- X sprintf(defname,"button%d",numbutt++);
- X
- X /* find label, name, action in tree */
- X object->name = get_value(root,"name",defname);
- X label = get_value(root,"label",object->name);
- X object->action = parse_actions(object->name,root);
- X button_info = (struct buttoninfo*) malloc( sizeof( struct buttoninfo ) );
- X /* save type (button, toggle) for use by callback routines */
- X button_info->type = strdupl(type);
- X /* save value for toggles */
- X button_info->value = get_value(root,"value",label);
- X if (!strcmp(button_info->type,"toggle")) {
- X object->value = strdupl("");
- X }else{
- X object->value = strdupl(button_info->value);
- X }
- X
- X narg = 0;
- X XtSetArg(args[narg], XtNlabel, label); narg++;
- X
- X /* common parameters */
- X common_tags(root,args,&narg,SET_ALL);
- X
- X if (!strcmp(type,"button"))
- X {
- X button = XtCreateManagedWidget(object->name,commandWidgetClass,
- X parent,args,narg);
- X } else {
- X button = XtCreateManagedWidget(object->name,toggleWidgetClass,
- X parent,args,narg);
- X }
- X
- X object->widgetname = button;
- X object->info = button_info;
- X object->updater = button_update;
- X
- X XtAddCallback( button, XtNcallback, button_callback, (XtPointer) object);
- }
- X
- /* callback used for buttons */
- void
- X button_callback(widget, client_data, callData)
- Widget widget;
- XXtPointer client_data, callData;
- {
- X Objdef *object;
- X struct buttoninfo *button_info;
- X extern int quitflag;
- X Arg arg[1];
- X Boolean state;
- X
- X object = (Objdef *) client_data;
- X button_info = (struct buttoninfo *) object->info;
- X
- X /* set toggle value if it is on */
- X if (!strcmp(button_info->type,"toggle"))
- X {
- X XtSetArg( arg[0], XtNstate, &state );
- X XtGetValues( object->widgetname, arg, ONE );
- X if (state == TRUE )
- X object->value = strdupl(button_info->value);
- X else
- X object->value = strdupl("");
- X }
- X
- X if ( perform_actions(object->name,object->action,1) && !quitflag )
- X quit_xtpanel();
- }
- X
- void button_update(object,value)
- Objdef* object;
- char* value;
- {
- X struct buttoninfo *button_info;
- X Arg arg[1];
- X Boolean state;
- X
- X button_info = (struct buttoninfo *) object->info;
- X
- X /* set toggle value if it is on */
- X if (!strcmp(button_info->type,"toggle"))
- X {
- X button_info->value = strdupl(value);
- X XtSetArg( arg[0], XtNstate, &state );
- X XtGetValues( object->widgetname, arg, ONE );
- X if (state == TRUE )
- X object->value = strdupl(button_info->value);
- X } else {
- X object->value = strdupl(value);
- X }
- }
- SHAR_EOF
- chmod 0664 xtpanel/button.c ||
- echo 'restore of xtpanel/button.c failed'
- Wc_c="`wc -c < 'xtpanel/button.c'`"
- test 4189 -eq "$Wc_c" ||
- echo 'xtpanel/button.c: original size 4189, current size' "$Wc_c"
- fi
- # ============= xtpanel/object.h ==============
- if test -f 'xtpanel/object.h' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/object.h (File already exists)'
- else
- echo 'x - extracting xtpanel/object.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/object.h' &&
- #ifndef OBJECT_H
- #define OBJECT_H
- X
- #include <X11/Intrinsic.h>
- X
- #include "actions.h"
- X
- typedef struct objdef {
- X char* name;
- X action* action;
- X char* value;
- X Widget widgetname;
- X void* info;
- X void (*updater)();
- X struct objdef* next;
- X } Objdef, *PObjdef;
- X
- #ifndef _NO_PROTO
- X
- extern Objdef* new_object();
- extern Objdef* find_by_name( char*);
- extern Objdef* find_by_widget( Widget );
- extern char* get_string( char* );
- extern void set_string( char*, char* );
- extern void all_actions(void);
- X
- #else
- X
- extern Objdef* new_object();
- extern Objdef* find_by_name();
- extern Objdef* find_by_widget();
- extern char* get_string();
- extern void set_string();
- extern void all_actions();
- X
- #endif
- X
- #endif
- SHAR_EOF
- chmod 0664 xtpanel/object.h ||
- echo 'restore of xtpanel/object.h failed'
- Wc_c="`wc -c < 'xtpanel/object.h'`"
- test 679 -eq "$Wc_c" ||
- echo 'xtpanel/object.h: original size 679, current size' "$Wc_c"
- fi
- # ============= xtpanel/INSTALL ==============
- if test -f 'xtpanel/INSTALL' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/INSTALL (File already exists)'
- else
- echo 'x - extracting xtpanel/INSTALL (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/INSTALL' &&
- To install xtpanel,
- X
- If you have a working imake setup (the recommended way).
- --------------------------------------------------------
- You should edit Imake.config to reflect where you wish
- the system xtpanel files to be installed. The default is to put them
- in the X11 library directory in a sub-directory called xtpanel.
- X
- Type "xmkmf -a"
- X or "imake" followed by "make Makefiles"
- X or whatever you use to invoke imake at your site.
- X
- Type "make" to build the software.
- X
- Type "make install " to install the software.
- X
- Type "make install.man" to install the man page.
- X
- X
- If you haven't figure out imake yet, or your vendor didn't provide it
- ----------------------------------------------------------------------
- Edit the NoImake.cpp file to reflect where your X11 include files and
- libraries live and where you want the software installed.
- X
- Type "NoImake"
- X or"NoImake MACH" where MACH is one of SUN4, RS6000, HP700 or DEC3100
- X
- Then follow the make steps as above. You may need to edit NoImake.cpp
- to make it work on your machine.
- X
- X
- Machines tested:
- ----------------
- X
- Sun 4, OS 4.1.1, MIT X11R5
- Sun 4, OS 4.1.1, Openwindows-3 (see the file OW3 for more info)
- Sun 3, OS 3.5, MIT X11R5
- DEC 3100, ULTRIX V4.2, MIT X11R5
- DEC 3100, ULTRIX V4.2, UWS V4.2 (with optional MIT compatible subset)
- IBM RS6000, AIX V3.2, MIT X11R5
- IBM RS6000, AIX V3.2, IBM X11R4
- HP 700, HP-UX 8.05, HP X11R4
- Convex C-1, OS 9.0, MIT X11R4
- SHAR_EOF
- chmod 0664 xtpanel/INSTALL ||
- echo 'restore of xtpanel/INSTALL failed'
- Wc_c="`wc -c < 'xtpanel/INSTALL'`"
- test 1423 -eq "$Wc_c" ||
- echo 'xtpanel/INSTALL: original size 1423, current size' "$Wc_c"
- fi
- # ============= xtpanel/dialog.c ==============
- if test -f 'xtpanel/dialog.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/dialog.c (File already exists)'
- else
- echo 'x - extracting xtpanel/dialog.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/dialog.c' &&
- /*
- X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
- X * University. Official permission to use this software is included in
- X * the documentation. It authorizes you to use this file for any
- X * non-commercial purpose, provided that this copyright notice is not
- X * removed and that any modifications made to this file are commented
- X * and dated in the style of the example below.
- X */
- X
- /*
- X *
- X * source file: ./xtpanel/dialog.c
- X *
- X * Steve Cole, Dave Nichols (SEP), August 28 1992
- X * Inserted this sample edit history entry.
- X * Please log any further modifications made to this file:
- X * Steve Cole, Dave Nichols (SEP), November 20 1992 - version 2.00
- X * 1) added new objects: toggle, scrollbar, graph.
- X * 2) added new actions: ASSIGN, SET.
- X * 3) objects can have multiple actions.
- X * 4) backquoted strings in actions get executed at action time.
- X */
- X
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- X
- #include <X11/Xaw/Cardinals.h>
- #include <X11/Xaw/Command.h>
- #include <X11/Xaw/Dialog.h>
- X
- #include "object.h"
- #include "tree.h"
- #include "builders.h"
- X
- /* translation table used for dialog widget */
- char trans[] =
- X "<Leave>: update_dialog()\n\
- X <Key>Return: return_key()";
- X
- void build_dialog(root,parent)
- X entry *root;
- X Widget parent;
- {
- X Objdef *object;
- X char *label;
- X Arg args[20];
- X Widget dialog, button;
- X char defname[12];
- X static int numdiag=1;
- X int narg;
- X extern void dialog_callback();
- X extern void dialog_update();
- X
- X /* create new object */
- X object = new_object();
- X
- X /* construct default dialog name */
- X sprintf(defname,"dialog%d",numdiag++);
- X
- X /* find label, name, action, etc. in tree */
- X object->name = get_value(root,"name",defname);
- X label = get_value(root,"label",object->name);
- X object->action = parse_actions(object->name,root);
- X object->value = get_value(root,"value","");
- X
- X narg=0;
- X XtSetArg(args[narg], XtNlabel, label ); narg++;
- X XtSetArg(args[narg], XtNvalue, object->value); narg++;
- X /* common parameters */
- X common_tags(root,args,&narg,SET_WIDTH|SET_FG|SET_BG|SET_BORDER);
- X
- X dialog = XtCreateManagedWidget(object->name,dialogWidgetClass,parent,
- X args,narg);
- X
- X object->widgetname = dialog;
- X object->updater = dialog_update;
- X
- X /* use translations to update value whenever mouse leaves dialog widget */
- X XtAugmentTranslations(dialog,XtParseTranslationTable(trans));
- X
- X /* add a button */
- X button = XtCreateManagedWidget(object->name,commandWidgetClass,
- X dialog,NULL,ZERO);
- X XtAddCallback(button, XtNcallback, dialog_callback,
- X (XtPointer) object );
- }
- X
- /*
- X * this routine gets called when the optional button of a dialog
- X * item is pressed
- X */
- void dialog_callback(widget, client_data, callData)
- X Widget widget;
- X XtPointer client_data, callData;
- {
- X Objdef *object;
- X Arg arg[1];
- X extern int quitflag;
- X
- X object = (Objdef *) client_data;
- X /* get the value of the dialog */
- X object->value =
- X strdupl((char *) XawDialogGetValueString(object->widgetname));
- X
- X if (perform_actions(object->name,object->action,1) && !quitflag)
- X quit_xtpanel();
- }
- X
- /*
- X * this routine gets called whenever we leave
- X * a dialog widget, to be sure its value is up to date
- X */
- void dialog_update_callback( w, event, params, num_params)
- X Widget w;
- X XEvent *event;
- X String *params;
- X Cardinal *num_params;
- {
- X Objdef* obj;
- X
- X obj = find_by_widget(w);
- X obj->value = strdupl((char *) XawDialogGetValueString(w));
- }
- X
- /*
- X * this routine gets called whenever we press return
- X * in a dialog widget.
- X */
- void return_key_callback( w, event, params, num_params)
- X Widget w;
- X XEvent *event;
- X String *params;
- X Cardinal *num_params;
- {
- X Objdef *object;
- X Widget dialog = XtParent(w);
- X extern int quitflag;
- X
- X object = find_by_widget(dialog);
- X /* get the value of the dialog */
- X object->value =
- X strdupl((char *) XawDialogGetValueString(object->widgetname));
- X
- X if (perform_actions(object->name,object->action,1) && !quitflag)
- X quit_xtpanel();
- X return;
- }
- X
- void dialog_update(object,value)
- Objdef *object;
- char *value;
- {
- X char *label;
- X Arg args[10];
- X int narg;
- X
- X narg=0;
- X XtSetArg(args[narg], XtNvalue, value); narg++;
- X XtSetValues(object->widgetname,args,narg);
- }
- SHAR_EOF
- chmod 0664 xtpanel/dialog.c ||
- echo 'restore of xtpanel/dialog.c failed'
- Wc_c="`wc -c < 'xtpanel/dialog.c'`"
- test 4381 -eq "$Wc_c" ||
- echo 'xtpanel/dialog.c: original size 4381, current size' "$Wc_c"
- fi
- # ============= xtpanel/list.c ==============
- if test -f 'xtpanel/list.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/list.c (File already exists)'
- else
- echo 'x - extracting xtpanel/list.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/list.c' &&
- /*
- X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
- X * University. Official permission to use this software is included in
- X * the documentation. It authorizes you to use this file for any
- X * non-commercial purpose, provided that this copyright notice is not
- X * removed and that any modifications made to this file are commented
- X * and dated in the style of the example below.
- X */
- X
- /*
- X *
- X * source file: ./xtpanel/list.c
- X *
- X * Steve Cole, Dave Nichols (SEP), August 28 1992
- X * Inserted this sample edit history entry.
- X * Please log any further modifications made to this file:
- X * Steve Cole, Dave Nichols (SEP), November 20 1992 - version 2.00
- X * 1) added new objects: toggle, scrollbar, graph.
- X * 2) added new actions: ASSIGN, SET.
- X * 3) objects can have multiple actions.
- X * 4) backquoted strings in actions get executed at action time.
- X */
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- X
- #include <X11/Xaw/Box.h>
- #include <X11/Xaw/Cardinals.h>
- #include <X11/Xaw/Label.h>
- #include <X11/Xaw/List.h>
- #include <X11/Xaw/Viewport.h>
- X
- #include "object.h"
- #include "item.h"
- #include "tree.h"
- #include "builders.h"
- X
- void build_list(root,parent)
- X entry *root;
- X Widget parent;
- {
- X Objdef *object;
- X entry *curr, *lower;
- X char *label, *value;
- X struct itemdef *item;
- X struct itemizedinfo *list_info;
- X Arg args[10];
- X int narg;
- X Widget box,viewport,list;
- X int first;
- X char defname[12];
- X static int numlist=1;
- X int nitem=0;
- X String * liststring = NULL;
- X int allocated_items = 0;
- X extern void list_callback();
- X extern void list_update();
- X
- X /* list gets its own box */
- X box = XtCreateManagedWidget("listbox",boxWidgetClass,parent,NULL,ZERO);
- X
- X /* create new object */
- X object = new_object();
- X
- X /* construct default button name */
- X sprintf(defname,"list%d",numlist++);
- X
- X /* find label, name, action in tree */
- X object->name = get_value(root,"name",defname);
- X label = get_value(root,"label",object->name);
- X object->action = parse_actions(object->name,root);
- X list_info = (struct itemizedinfo*)
- X malloc( sizeof( struct itemizedinfo ) );
- X list_info->firstitem = (struct itemdef*) 0;
- X object->info = list_info;
- X
- X /* the list label */
- X narg = 0;
- X XtSetArg(args[narg], XtNborderWidth, 0); narg++;
- X XtSetArg(args[narg], XtNlabel, label); narg++;
- X (void) XtCreateManagedWidget(object->name,labelWidgetClass,
- X box,args,narg);
- X
- X /* create the list in a viewport */
- X narg=0;
- X XtSetArg(args[narg], XtNallowHoriz, TRUE ); narg++;
- X XtSetArg(args[narg], XtNallowVert, TRUE ); narg++;
- X /* common parameters */
- X common_tags(root,args,&narg,SET_ALL);
- X
- X viewport = XtCreateManagedWidget( object->name,viewportWidgetClass,
- X box,args,narg);
- X narg=0;
- X /* common parameters */
- X common_tags(root,args,&narg,SET_ALL);
- X list = XtCreateManagedWidget(object->name,listWidgetClass,viewport,
- X args,narg);
- X
- X /* first parse any itemlist entries into items */
- X parse_itemlist( root );
- X
- X /* loop over again to get items */
- X for (curr = get_next(root,"item",(entry*) 0), nitem=0;
- X curr != ((entry*) 0);
- X curr = get_next(root,"item",curr), nitem++){
- X
- X /* construct default item name */
- X sprintf(defname,"item%d",nitem+1);
- X
- X /* allocate structure to hold info for list item */
- X item = new_item(list_info);
- X
- X /* find label, value in the next level of the tree */
- X label = get_value(curr,"label",defname);
- X item->value = get_value(curr,"value",label);
- X
- X /* add an item */
- X if (nitem == allocated_items) {
- X allocated_items += 5;
- X liststring = (String *) XtRealloc((char *)liststring,
- X sizeof(String) * allocated_items);
- X }
- X liststring[nitem] = XtNewString(label);
- X XawListChange(list, liststring, nitem+1, 0, True);
- X
- X item->label = strdupl(label);
- X item->widgetname = list;
- X /* callback routine needs to know the object name */
- X item->object = object;
- X
- X /* info structure points to first item for find_item routine */
- X if (nitem == 0) list_info->firstitem = item;
- X
- X /* value is default; we select the button whose value matches this */
- X if (nitem == 0) value = get_value(root,"value",item->value);
- X
- X }
- X
- X /* loop over items - look for one that matches the default */
- X for (item = list_info->firstitem,nitem=0;
- X item != (struct itemdef*) 0; item=item->next,nitem++) {
- X if (!strcmp(item->value,value)) {
- X XawListHighlight(list,nitem);
- X object->value = value;
- X }
- X }
- X
- X XtAddCallback( list, XtNcallback, list_callback, (XtPointer) object );
- X object->widgetname = list;
- X object->updater = list_update;
- }
- X
- void
- X list_callback(widget, client_data, callData)
- Widget widget;
- XXtPointer client_data, callData;
- {
- X Objdef *object;
- X XawListReturnStruct *item;
- X struct itemdef *listitem;
- X Arg arg[1];
- X int num;
- X extern int quitflag;
- X
- X object = (Objdef *) client_data;
- X /* XawListReturnStruct just tells us the label */
- X item = (XawListReturnStruct *) callData;
- X
- X /* find the item whose label matches */
- X listitem = find_item(object,item->string);
- X
- X /* get the value of the text field */
- X object->value = strdupl((char *) listitem->value);
- X
- X if (perform_actions(object->name,object->action,1) && !quitflag)
- X quit_xtpanel();
- }
- X
- void list_update(object,value)
- Objdef *object;
- char *value;
- {
- X struct itemdef *item;
- X struct itemizedinfo *list_info;
- X Arg args[10];
- X int narg;
- X int nitem=0;
- X
- X list_info = object->info;
- X
- X /* loop over items - look for one that matches the value */
- X for (item = list_info->firstitem,nitem=0;
- X item != (struct itemdef*) 0; item=item->next,nitem++) {
- X if (!strcmp(item->value,value)) {
- X XawListHighlight(object->widgetname,nitem);
- X object->value = value;
- X }
- X }
- X
- }
- SHAR_EOF
- chmod 0664 xtpanel/list.c ||
- echo 'restore of xtpanel/list.c failed'
- Wc_c="`wc -c < 'xtpanel/list.c'`"
- test 5904 -eq "$Wc_c" ||
- echo 'xtpanel/list.c: original size 5904, current size' "$Wc_c"
- fi
- # ============= xtpanel/xtpanel-examples.script.sed ==============
- if test -f 'xtpanel/xtpanel-examples.script.sed' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/xtpanel-examples.script.sed (File already exists)'
- else
- echo 'x - extracting xtpanel/xtpanel-examples.script.sed (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/xtpanel-examples.script.sed' &&
- #!/bin/csh -f
- X
- if( ! -d SYS_XTPANELDIR/examples ) then
- X echo ""
- X echo " It looks like someone has moved the system xtpanel directory"
- X echo " It used to be in SYS_XTPANELDIR/examples "
- X echo " You need to update this shell ( $0 ) "
- X echo " by rebuilding the software."
- X echo ""
- X exit -1
- endif
- X
- cd SYS_XTPANELDIR/examples
- X
- xtpanel < all_examples
- SHAR_EOF
- chmod 0664 xtpanel/xtpanel-examples.script.sed ||
- echo 'restore of xtpanel/xtpanel-examples.script.sed failed'
- Wc_c="`wc -c < 'xtpanel/xtpanel-examples.script.sed'`"
- test 360 -eq "$Wc_c" ||
- echo 'xtpanel/xtpanel-examples.script.sed: original size 360, current size' "$Wc_c"
- fi
- # ============= xtpanel/item.h ==============
- if test -f 'xtpanel/item.h' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/item.h (File already exists)'
- else
- echo 'x - extracting xtpanel/item.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/item.h' &&
- #ifndef ITEM_H
- #define ITEM_H
- X
- #include "object.h"
- X
- typedef struct itemizedinfo {
- X struct itemdef* firstitem;
- X };
- X
- typedef struct itemdef {
- X char* label;
- X char* value;
- X Widget widgetname;
- X Objdef* object;
- X struct itemdef* next;
- X } _idef;
- X
- X
- #ifndef _NO_PROTO
- X
- extern struct itemdef* find_item( Objdef*, char * );
- extern struct itemdef* new_item( struct itemizedinfo* info );
- X
- #else
- X
- extern struct itemdef* find_item();
- extern struct itemdef* new_item();
- X
- #endif
- X
- X
- X
- #endif
- SHAR_EOF
- chmod 0664 xtpanel/item.h ||
- echo 'restore of xtpanel/item.h failed'
- Wc_c="`wc -c < 'xtpanel/item.h'`"
- test 471 -eq "$Wc_c" ||
- echo 'xtpanel/item.h: original size 471, current size' "$Wc_c"
- fi
- # ============= xtpanel/menubutton.c ==============
- if test -f 'xtpanel/menubutton.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/menubutton.c (File already exists)'
- else
- echo 'x - extracting xtpanel/menubutton.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/menubutton.c' &&
- /*
- X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
- X * University. Official permission to use this software is included in
- X * the documentation. It authorizes you to use this file for any
- X * non-commercial purpose, provided that this copyright notice is not
- X * removed and that any modifications made to this file are commented
- X * and dated in the style of the example below.
- X */
- X
- /*
- X *
- X * source file: ./xtpanel/menubutton.c
- X *
- X * Steve Cole, Dave Nichols (SEP), August 28 1992
- X * Inserted this sample edit history entry.
- X * Please log any further modifications made to this file:
- X * Steve Cole, Dave Nichols (SEP), November 20 1992 - version 2.00
- X * 1) added new objects: toggle, scrollbar, graph.
- X * 2) added new actions: ASSIGN, SET.
- X * 3) objects can have multiple actions.
- X * 4) backquoted strings in actions get executed at action time.
- X */
- X
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- #include <X11/bitmaps/dot>
- X
- #include <X11/Xaw/Cardinals.h>
- #include <X11/Xaw/MenuButton.h>
- #include <X11/Xaw/SimpleMenu.h>
- #include <X11/Xaw/SmeBSB.h>
- X
- #include "object.h"
- #include "item.h"
- #include "tree.h"
- #include "builders.h"
- X
- void build_menubutton(root,parent)
- X entry *root;
- X Widget parent;
- {
- X Objdef *object;
- X entry *curr, *lower;
- X char *label, *value;
- X struct itemizedinfo *menu_info;
- X struct itemdef *item;
- X Arg args[10];
- X int narg;
- X Widget button, menu, menuitem;
- X int first;
- X char defname[14];
- X static int nummenu=1;
- X int nitem=0;
- X Pixmap mark;
- X extern void menubutton_callback();
- X extern void menubutton_update();
- X
- X /* create new object */
- X object = new_object();
- X
- X /* construct default button name */
- X sprintf(defname,"menubutton%d",nummenu++);
- X
- X /* find label, name, action in tree */
- X object->name = get_value(root,"name",defname);
- X label = get_value(root,"label",object->name);
- X object->action = parse_actions(object->name,root);
- X menu_info = (struct itemizedinfo*)
- X malloc( sizeof( struct itemizedinfo ) );
- X menu_info->firstitem = (struct itemdef*) 0;
- X
- X object->info = menu_info;
- X object->updater = menubutton_update;
- X
- X /* create the button and the menu */
- X narg = 0;
- X XtSetArg(args[narg], XtNlabel, label); narg++;
- X /* common parameters */
- X common_tags(root,args,&narg,SET_ALL);
- X
- X button = XtCreateManagedWidget(object->name,menuButtonWidgetClass,
- X parent,args,narg);
- X menu = XtCreatePopupShell("menu",simpleMenuWidgetClass,button,NULL,ZERO);
- X
- X /* first parse any itemlist entries into items */
- X parse_itemlist( root );
- X
- X /* loop over again to get items */
- X for (curr = get_next(root,"item",(entry*) 0), nitem=0;
- X curr != ((entry*) 0);
- X curr = get_next(root,"item",curr), nitem++){
- X
- X /* construct default item name */
- X sprintf(defname,"item%d",nitem+1);
- X
- X /* allocate structure to hold info for menu item */
- X item = new_item(menu_info);
- X
- X /* find label, value in the next level of the tree */
- X label = get_value(curr,"label",defname);
- X item->value = get_value(curr,"value",label);
- X
- X /* add an item */
- X narg = 0;
- X
- X /* common parameters */
- X common_tags(curr,args,&narg,SET_ALL);
- X
- X XtSetArg(args[narg], XtNlabel, label); narg++;
- X menuitem = XtCreateManagedWidget(object->name,smeBSBObjectClass,
- X menu,args,narg);
- X
- X XtAddCallback( menuitem, XtNcallback, menubutton_callback,
- X (XtPointer) item );
- X
- X item->label = strdupl(label);
- X item->widgetname = menuitem;
- X /* callback routine needs to know the object name */
- X item->object = object;
- X
- X /* info structure points to first item for find_item routine */
- X if (nitem == 0) menu_info->firstitem = item;
- X
- X /* value is default; we select the button whose value matches this */
- X if (nitem == 0) value = get_value(root,"value",item->value);
- X
- X /* check to see if this is the default item */
- X /* indicate the default item with an X */
- X narg = 0;
- X
- X if (!strcmp(value,item->value)) {
- X mark = XCreateBitmapFromData(XtDisplay(parent),
- X RootWindowOfScreen(XtScreen(parent)),
- X (char *) dot_bits,
- X dot_width, dot_height);
- X XtSetArg(args[narg], XtNleftBitmap, mark); narg++;
- X object->value = value;
- X XtSetValues(menuitem,args,narg);
- X }
- X }
- }
- X
- extern Widget toplevel;
- X
- void
- X menubutton_callback(widget, client_data, callData)
- Widget widget;
- XXtPointer client_data, callData;
- {
- X Objdef *object;
- X struct itemdef *menuitem;
- X struct itemizedinfo *menu_info;
- X Arg args[10];
- X int narg;
- X Pixmap mark;
- X extern int quitflag;
- X extern void unmark_all_items();
- X
- X menuitem = (struct itemdef *) client_data;
- X object = (Objdef *) menuitem->object;
- X menu_info = (struct itemizedinfo *) object->info;
- X
- X /* first unmark the previous choice, if any */
- X unmark_all_items(menu_info);
- X
- X object->value = strdupl((char *) menuitem->value);
- X if (perform_actions(object->name,object->action,1) && !quitflag)
- X quit_xtpanel();
- X
- X /* indicate the current choice */
- X mark = XCreateBitmapFromData(XtDisplay(toplevel),
- X RootWindowOfScreen(XtScreen(toplevel)),
- X (char *) dot_bits,
- X dot_width, dot_height);
- X narg = 0;
- X XtSetArg(args[narg], XtNleftBitmap, mark); narg++;
- X XtSetValues(menuitem->widgetname,args,narg);
- X
- }
- X
- void
- X unmark_all_items(menu_info)
- struct itemizedinfo *menu_info;
- {
- X struct itemdef *item;
- X Arg args[10];
- X int narg;
- X
- X for( item=menu_info->firstitem;
- X item != (struct itemdef*)0;
- X item = item->next )
- X {
- X narg = 0;
- X XtSetArg(args[narg], XtNleftBitmap, None); narg++;
- X XtSetValues(item->widgetname,args,narg);
- X }
- }
- X
- void
- X menubutton_update(object,value)
- Objdef* object;
- char* value;
- {
- X struct itemizedinfo *menu_info;
- X struct itemdef *item;
- X Arg args[10];
- X int narg;
- X Pixmap mark;
- X
- X menu_info = object->info;
- X
- X for( item=menu_info->firstitem;
- X item != (struct itemdef*)0;
- X item = item->next )
- X {
- X if (!strcmp(item->value,value)) {
- X unmark_all_items(menu_info);
- X narg = 0;
- X XtSetArg(args[narg], XtNleftBitmap, None); narg++;
- X XtSetValues(item->widgetname,args,narg);
- X mark = XCreateBitmapFromData(XtDisplay(toplevel),
- X RootWindowOfScreen(XtScreen(toplevel)),
- X (char *) dot_bits,
- X dot_width, dot_height);
- X narg = 0;
- X XtSetArg(args[narg], XtNleftBitmap, mark); narg++;
- X XtSetValues(item->widgetname,args,narg);
- X }
- X }
- }
- SHAR_EOF
- chmod 0664 xtpanel/menubutton.c ||
- echo 'restore of xtpanel/menubutton.c failed'
- Wc_c="`wc -c < 'xtpanel/menubutton.c'`"
- test 6487 -eq "$Wc_c" ||
- echo 'xtpanel/menubutton.c: original size 6487, current size' "$Wc_c"
- fi
- # ============= xtpanel/message.c ==============
- if test -f 'xtpanel/message.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/message.c (File already exists)'
- else
- echo 'x - extracting xtpanel/message.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/message.c' &&
- /*
- X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
- X * University. Official permission to use this software is included in
- X * the documentation. It authorizes you to use this file for any
- X * non-commercial purpose, provided that this copyright notice is not
- X * removed and that any modifications made to this file are commented
- X * and dated in the style of the example below.
- X */
- X
- /*
- X *
- X * source file: ./xtpanel/message.c
- X *
- X * Steve Cole, Dave Nichols (SEP), August 28 1992
- X * Inserted this sample edit history entry.
- X * Please log any further modifications made to this file:
- X * Steve Cole, Dave Nichols (SEP), November 20 1992 - version 2.00
- X * 1) added new objects: toggle, scrollbar, graph.
- X * 2) added new actions: ASSIGN, SET.
- X * 3) objects can have multiple actions.
- X * 4) backquoted strings in actions get executed at action time.
- X */
- X
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- X
- #include <X11/Xaw/Cardinals.h>
- #include <X11/Xaw/Label.h>
- X
- #include "object.h"
- #include "tree.h"
- #include "builders.h"
- X
- void build_message(root,parent)
- X entry *root;
- X Widget parent;
- {
- X Objdef *object;
- X char *name,*label;
- X Widget message;
- X Arg args[10];
- X int narg;
- X char defname[12];
- X int numess=1;
- X extern void message_update();
- X
- X /* create new object */
- X object = new_object();
- X
- X /* construct default dialog name */
- X sprintf(defname,"message%d",numess++);
- X
- X /* find label, name in tree */
- X object->name = get_value(root,"name",defname);
- X object->value = get_value(root,"value","");
- X
- X /* messages do not have a border drawn around them */
- X narg = 0;
- X XtSetArg(args[narg], XtNborderWidth, 0); narg++;
- X XtSetArg(args[narg], XtNlabel, object->value); narg++;
- X /* common parameters */
- X common_tags(root,args,&narg,SET_ALL);
- X
- X message = XtCreateManagedWidget(object->name,labelWidgetClass,
- X parent,args,narg);
- X
- X object->widgetname = message;
- X object->updater = message_update;
- }
- X
- void message_update(object,value)
- Objdef* object;
- char* value;
- {
- X Arg args[10];
- X int narg;
- X
- X narg = 0;
- X XtSetArg(args[narg], XtNlabel, value); narg++;
- X XtSetValues(object->widgetname,args,narg);
- }
- X
- SHAR_EOF
- chmod 0664 xtpanel/message.c ||
- echo 'restore of xtpanel/message.c failed'
- Wc_c="`wc -c < 'xtpanel/message.c'`"
- test 2221 -eq "$Wc_c" ||
- echo 'xtpanel/message.c: original size 2221, current size' "$Wc_c"
- fi
- # ============= xtpanel/slider.c ==============
- if test -f 'xtpanel/slider.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/slider.c (File already exists)'
- else
- echo 'x - extracting xtpanel/slider.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/slider.c' &&
- /*
- X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
- X * University. Official permission to use this software is included in
- X * the documentation. It authorizes you to use this file for any
- X * non-commercial purpose, provided that this copyright notice is not
- X * removed and that any modifications made to this file are commented
- X * and dated in the style of the example below.
- X */
- X
- /*
- X *
- X * source file: ./xtpanel/slider.c
- X *
- X * Steve Cole, Dave Nichols (SEP), August 28 1992
- X * Inserted this sample edit history entry.
- X * Please log any further modifications made to this file:
- X * Steve Cole, Dave Nichols (SEP), November 20 1992 - version 2.00
- X * 1) added new objects: toggle, scrollbar, graph.
- X * 2) added new actions: ASSIGN, SET.
- X * 3) objects can have multiple actions.
- X * 4) backquoted strings in actions get executed at action time.
- X */
- X
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- X
- #include <X11/Xaw/Box.h>
- #include <X11/Xaw/Cardinals.h>
- #include <X11/Xaw/Command.h>
- #include <X11/Xaw/Label.h>
- #include <X11/Xaw/Scrollbar.h>
- X
- #include "object.h"
- #include "tree.h"
- #include "builders.h"
- X
- #include <stdio.h>
- X
- typedef struct sliderinfo {
- X float minval;
- X float maxval;
- X Widget label;
- X char* format;
- X char* type;
- };
- X
- void build_slider(root,parent,type)
- X entry *root;
- X Widget parent;
- X char *type;
- {
- X Objdef *object;
- X entry *curr;
- X char* label;
- X struct sliderinfo *slider_info;
- X Arg args[10];
- X int narg;
- X Widget box, scrollbar, vlabel, button;
- X float valmin,valmax,val,top;
- X char text[100];
- X int width,height;
- X char *orient;
- X char defname[12];
- X static int numslid=1;
- X static int numscroll=1;
- X extern void slider_button_callback();
- X extern void slider_jump_callback();
- X extern void slider_scroll_callback();
- X extern void slider_update();
- X
- X /* slider gets its own box */
- X if (!strcmp(type,"slider")) {
- X narg = 0;
- X box = XtCreateManagedWidget("sliderbox",boxWidgetClass,
- X parent,args,narg);
- X }
- X else {
- X box = parent;
- X }
- X
- X /* create new object */
- X object = new_object();
- X
- X /* construct default slider name */
- X if (!strcmp(type,"slider")) {
- X sprintf(defname,"slider%d",numslid++);
- X } else {
- X sprintf(defname,"scrollbar%d",numscroll++);
- X }
- X
- X /* find label, name, action in tree */
- X object->name = get_value(root,"name",defname);
- X label = get_value(root,"label",object->name);
- X object->action = parse_actions(object->name,root);
- X slider_info = (struct sliderinfo*)
- X malloc( sizeof( struct sliderinfo ) );
- X object->info = slider_info;
- X slider_info->minval = ((float) atof(get_value(root,"min","0")));
- X slider_info->maxval = ((float) atof(get_value(root,"max","1")));
- X slider_info->label = (Widget)0;
- X /* slider value defaults to minimum */
- X val = (float) atof(get_value(root,"value",get_value(root,"min","0")));
- X slider_info->format = get_value(root,"format","%f");
- X /* save type (scrollbar, slider) for use by callback routines */
- X slider_info->type = strdupl(type);
- X
- X /* the slider label */
- X /* for type scrollbar, no label is displayed */
- X if (!strcmp(type,"slider")) {
- X narg = 0;
- X XtSetArg(args[narg], XtNlabel, label); narg++;
- X XtSetArg(args[narg], XtNborderWidth, 0); narg++;
- X (void) XtCreateManagedWidget(object->name,labelWidgetClass,box,
- X args,narg);
- X }
- X
- X /* determine the correct starting point for the slider */
- X narg = 0;
- X top = val/slider_info->maxval;
- X if (sizeof(float) > sizeof(XtArgVal))
- X {
- X XtSetArg(args[narg], XtNtopOfThumb, top); narg++;
- X }
- X else
- X {
- X XtArgVal * l_top = (XtArgVal *) ⊤
- X XtSetArg(args[narg], XtNtopOfThumb, *l_top); narg++;
- X }
- X
- X /* common parameters */
- X common_tags(root,args,&narg,SET_FG|SET_BG|SET_BORDER);
- X
- X /* height, width, orient */
- X /* done here instead of common_tags so we could have defaults */
- X height = (int) atoi(get_value(root,"height","25"));
- X width = (int) atoi(get_value(root,"width","100"));
- X orient = get_value(root,"orientation","horizontal");
- X XtSetArg(args[narg], XtNlength, width); narg++;
- X XtSetArg(args[narg], XtNthickness, height); narg++;
- X /* the SetTag routine in builders.c does the necessary conversion */
- X SetTag(box,args,&narg,"orientation",orient);
- X
- X /* slider is actually an athena scrollbar widget */
- X scrollbar = XtCreateManagedWidget(object->name,scrollbarWidgetClass,
- X box,args,narg);
- X
- X /* jump callback is for middle mouse button */
- X XtAddCallback( scrollbar, XtNjumpProc, slider_jump_callback,
- X (XtPointer) object );
- X
- X /* scroll callback is for incremental scrolling with left and
- X right buttons */
- X XtAddCallback( scrollbar, XtNscrollProc, slider_scroll_callback,
- X (XtPointer) object );
- X
- X /* set to the correct starting point */
- X (void) XawScrollbarSetThumb(scrollbar,
- X (val-slider_info->minval)/
- X (slider_info->maxval-slider_info->minval),-1.);
- X
- X /* add a button to print out slider value */
- X if (!strcmp(type,"slider")) {
- X button = XtCreateManagedWidget(object->name,commandWidgetClass,box,
- X NULL,ZERO);
- X XtAddCallback(button, XtNcallback, slider_button_callback,
- X (XtPointer) object );
- X }
- X
- X sprintf( text, slider_info->format, (float) val);
- X object->value = strdupl(text);
- X object->widgetname = scrollbar;
- X object->updater = slider_update;
- X
- X /* indicate the slider value using another label */
- X if (!strcmp(type,"slider")) {
- X narg = 0;
- X XtSetArg( args[narg], XtNlabel, object->value); narg++;
- X vlabel = XtCreateManagedWidget(object->name,labelWidgetClass,box,
- X args,narg);
- X slider_info->label = vlabel;
- X }
- }
- X
- void
- X slider_jump_callback(widget, client_data, top_ptr)
- Widget widget;
- XXtPointer client_data, top_ptr;
- {
- X Objdef *object;
- X struct sliderinfo *slider_info;
- X Arg arg[1];
- X char text[20];
- X /* top is new location of slider */
- X float top = *((float *) top_ptr);
- X object = (Objdef *) client_data;
- X slider_info = (struct sliderinfo *) object->info;
- X /* compute new value */
- X sprintf( text, slider_info->format,
- X (float) slider_info->minval +
- X top*(slider_info->maxval - slider_info->minval));
- X object->value = strdupl(text);
- X /* set the label to the new value */
- X if (slider_info->label != (Widget) 0) {
- X XtSetArg( arg[0], XtNlabel, text );
- X XtSetValues( slider_info->label, arg, ONE );
- X }
- X if (!strcmp(slider_info->type,"scrollbar"))
- X perform_actions(object->name,object->action,1);
- }
- X
- void
- X slider_scroll_callback(widget, client_data, pos_ptr)
- Widget widget;
- XXtPointer client_data, pos_ptr;
- {
- X Objdef *object;
- X struct sliderinfo *slider_info;
- X Arg arg[1];
- X char text[10];
- X float top;
- X Dimension len;
- X int pos;
- X pos = (int) pos_ptr;
- X object = (Objdef *) client_data;
- X slider_info = (struct sliderinfo *) object->info;
- X /* get the current position of the slider */
- X XtSetArg( arg[0], XtNtopOfThumb, &top );
- X XtGetValues( object->widgetname, arg, ONE );
- X /* now compute new position - 5% change */
- X top -= pos/abs(pos) * 0.05;
- X if (top > 1.) top = 1.;
- X if (top < 0.) top = 0.;
- X /* compute new value */
- X sprintf( text, slider_info->format,
- X (float) slider_info->minval +
- X top*(slider_info->maxval - slider_info->minval));
- X object->value = strdupl(text);
- X /* update label */
- X if (slider_info->label != (Widget) 0) {
- X XtSetArg( arg[0], XtNlabel, text );
- X XtSetValues( slider_info->label, arg, ONE );
- X }
- X /* update the slider */
- X if (sizeof(float) > sizeof(XtArgVal))
- X {
- X XtSetArg(arg[0], XtNtopOfThumb, top);
- X }
- X else
- X {
- X XtArgVal * l_top = (XtArgVal *) ⊤
- X XtSetArg(arg[0], XtNtopOfThumb, *l_top);
- X }
- X XtSetValues( object->widgetname, arg, ONE );
- X if (!strcmp(slider_info->type,"scrollbar"))
- X perform_actions(object->name,object->action,1);
- }
- X
- /* called when ok button of slider is pressed */
- void
- X slider_button_callback(widget, client_data, callData)
- Widget widget;
- XXtPointer client_data, callData;
- {
- X Objdef *object;
- X extern int quitflag;
- X
- X object = (Objdef *) client_data;
- X if ( perform_actions(object->name,object->action,1) && !quitflag )
- X quit_xtpanel();
- }
- X
- void
- X slider_update(object, value)
- Objdef *object;
- char *value;
- {
- X struct sliderinfo *slider_info;
- X Arg arg[1];
- X char text[10];
- X float top,val;
- X Dimension len;
- X int pos;
- X
- X slider_info = (struct sliderinfo *) object->info;
- X sscanf( value,"%f",&val);
- X top = (val - slider_info->minval)/
- X (slider_info->maxval-slider_info->minval);
- X if (top > 1.) top = 1.;
- X if (top < 0.) top = 0.;
- X /* compute new value */
- X sprintf( text, slider_info->format,
- X (float) slider_info->minval +
- X top*(slider_info->maxval - slider_info->minval));
- X object->value = strdupl(text);
- X /* update label */
- X if (slider_info->label != (Widget) 0) {
- X XtSetArg( arg[0], XtNlabel, text );
- X XtSetValues( slider_info->label, arg, ONE );
- X }
- X /* update the slider */
- X if (sizeof(float) > sizeof(XtArgVal))
- X {
- X XtSetArg(arg[0], XtNtopOfThumb, top);
- X }
- X else
- X {
- X XtArgVal * l_top = (XtArgVal *) ⊤
- X XtSetArg(arg[0], XtNtopOfThumb, *l_top);
- X }
- X XtSetValues( object->widgetname, arg, ONE );
- }
- SHAR_EOF
- chmod 0664 xtpanel/slider.c ||
- echo 'restore of xtpanel/slider.c failed'
- Wc_c="`wc -c < 'xtpanel/slider.c'`"
- test 9457 -eq "$Wc_c" ||
- echo 'xtpanel/slider.c: original size 9457, current size' "$Wc_c"
- fi
- # ============= xtpanel/Imake.config ==============
- if test -f 'xtpanel/Imake.config' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/Imake.config (File already exists)'
- else
- echo 'x - extracting xtpanel/Imake.config (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/Imake.config' &&
- X
- /* This is the directory where the system xtpanel files will be installed */
- SYS_XTPANELDIR = $(LIBDIR)/xtpanel
- #ifdef OW3
- IMAKE_DEFINES = -DLibDir=/usr/openwin/lib -DIncRoot=/usr/openwin/include
- #endif
- X
- SHAR_EOF
- chmod 0664 xtpanel/Imake.config ||
- echo 'restore of xtpanel/Imake.config failed'
- Wc_c="`wc -c < 'xtpanel/Imake.config'`"
- test 205 -eq "$Wc_c" ||
- echo 'xtpanel/Imake.config: original size 205, current size' "$Wc_c"
- fi
- # ============= xtpanel/choice.c ==============
- if test -f 'xtpanel/choice.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/choice.c (File already exists)'
- else
- echo 'x - extracting xtpanel/choice.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/choice.c' &&
- /*
- X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
- X * University. Official permission to use this software is included in
- X * the documentation. It authorizes you to use this file for any
- X * non-commercial purpose, provided that this copyright notice is not
- X * removed and that any modifications made to this file are commented
- X * and dated in the style of the example below.
- X */
- X
- /*
- X *
- X * source file: ./xtpanel/choice.c
- X *
- X * Steve Cole, Dave Nichols (SEP), August 28 1992
- X * Inserted this sample edit history entry.
- X * Please log any further modifications made to this file:
- X * Steve Cole, Dave Nichols (SEP), November 20 1992 - version 2.00
- X * 1) added new objects: toggle, scrollbar, graph.
- X * 2) added new actions: ASSIGN, SET.
- X * 3) objects can have multiple actions.
- X * 4) backquoted strings in actions get executed at action time.
- X */
- X
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- X
- #include <X11/Xaw/Box.h>
- #include <X11/Xaw/Cardinals.h>
- #include <X11/Xaw/Label.h>
- #include <X11/Xaw/Toggle.h>
- X
- #include "object.h"
- #include "item.h"
- #include "tree.h"
- #include "builders.h"
- X
- typedef struct choicedef {
- X char* value;
- X Widget widgetname;
- X Objdef* object;
- X struct choicedef* next;
- } _cdef;
- X
- /* translation table used for toggle widgets in a choice object */
- char choice_trans[] =
- X "<EnterWindow>: highlight(Always)\n\
- X <LeaveWindow>: unhighlight()\n\
- X <Btn1Down>,<Btn1Up>: set() notify()";
- X
- void build_choice(root,parent)
- X entry *root;
- X Widget parent;
- {
- X Objdef *object;
- X entry *curr;
- X struct itemdef *item;
- X struct itemizedinfo *choice_info;
- X char *label,*value;
- X Arg args[20];
- X int narg;
- X Widget box,labl,choice1,choice2;
- X char defname[12];
- X static int numtog=1;
- X int nitem;
- X extern void choice_callback();
- X extern void choice_update();
- X
- X narg = 0;
- X /* common parameters */
- X common_tags(root,args,&narg,SET_BG | SET_ORIENT);
- X
- X /* choice object gets its own box */
- X box = XtCreateManagedWidget("choicebox",boxWidgetClass,parent,args,narg);
- X
- X /* create new object */
- X object = new_object();
- X
- X /* construct default button name */
- X sprintf(defname,"choice%d",numtog++);
- X
- X /* find label, name, action in tree */
- X object->name = get_value(root,"name",defname);
- X label = get_value(root,"label",object->name);
- X object->action = parse_actions(object->name,root);
- X
- X choice_info = (struct itemizedinfo*)
- X malloc( sizeof( struct itemizedinfo));
- X choice_info->firstitem = (struct itemdef*) 0;
- X object->info = choice_info;
- X
- X /* make the label */
- X /* if label is blank, skip displaying it */
- X if (strcmp(label,"")) {
- X narg = 0;
- X XtSetArg(args[narg], XtNborderWidth, 0); narg++;
- X XtSetArg(args[narg], XtNlabel, label); narg++;
- X /* common parameters */
- X common_tags(root,args,&narg,SET_ALL);
- X
- X labl = XtCreateManagedWidget(object->name,labelWidgetClass,box,
- X args,narg);
- X }
- X
- X /* first parse any itemlist entries into items */
- X parse_itemlist( root );
- X
- X /* loop over items */
- X for (curr = get_next(root,"item",(entry*) 0), nitem=0;
- X curr != ((entry*) 0);
- X curr = get_next(root,"item",curr), nitem++){
- X
- X /* construct default item name */
- X sprintf(defname,"item%d",nitem+1);
- X
- X /* allocate structure to hold info for choice item */
- X item = new_item(choice_info);
- X
- X /* find label, value in the next level of the tree */
- X label = get_value(curr,"label",defname);
- X item->value = get_value(curr,"value",label);
- X
- X /* value is default; we set a button to on if its value matches this */
- X if (nitem == 0) value = get_value(root,"value",item->value);
- X
- X /* check to see if this is the default item */
- X /* choice object always needs to have one button set */
- X narg = 0;
- X if (!strcmp(value,item->value)) {
- X XtSetArg(args[narg], XtNstate, True); narg++;
- X object->value = item->value;
- X }
- X
- X /* first button stands alone; others have to point to it
- X with radioGroup */
- X if (nitem == 0) {
- X XtSetArg(args[narg], XtNlabel, label); narg++;
- X /* radioData is used by choice_update routine */
- X XtSetArg(args[narg], XtNradioData, item->value); narg++;
- X /* common parameters */
- X common_tags(curr,args,&narg,SET_ALL);
- X
- X choice1 = XtCreateManagedWidget(object->name,toggleWidgetClass,box,
- X args,narg);
- X /* use translations */
- X XtOverrideTranslations(choice1,
- X XtParseTranslationTable(choice_trans));
- X XtAddCallback(choice1, XtNcallback,choice_callback,
- X (XtPointer)item );
- X item->widgetname = choice1;
- X }
- X else {
- X XtSetArg(args[narg], XtNradioGroup, choice1); narg++;
- X XtSetArg(args[narg], XtNlabel, label); narg++;
- X XtSetArg(args[narg], XtNradioData, item->value); narg++;
- X /* common parameters */
- X common_tags(curr,args,&narg,SET_ALL);
- X
- X choice2 = XtCreateManagedWidget(object->name,toggleWidgetClass,
- X box,args,narg);
- X
- X /* use translations */
- X XtOverrideTranslations(choice2,
- X XtParseTranslationTable(choice_trans));
- X XtAddCallback(choice2, XtNcallback,choice_callback,
- X (XtPointer)item );
- X item->widgetname = choice2;
- X }
- X
- X item->object = object;
- X item->label = strdupl(label);
- X if (nitem == 0) choice_info->firstitem = item;
- X
- X /* set object->widgetname to any of the choice widgets */
- X /* for use by choice_update */
- X object->widgetname = choice1;
- X object->updater = choice_update;
- X }
- }
- X
- void choice_callback(widget, client_data, callData)
- X Widget widget;
- X XtPointer client_data, callData;
- {
- X Objdef *object;
- X struct itemdef *item;
- X Arg arg[1];
- X Boolean state;
- X extern int quitflag;
- X
- X item = (struct itemdef *) client_data;
- X object = (Objdef *) item->object;
- X /* get current state of button */
- X XtSetArg( arg[0], XtNstate, &state );
- X XtGetValues( item->widgetname, arg, ONE );
- X /* if button is now selected, perform its action */
- X if (state == TRUE)
- X {
- X object->value = strdupl((char *) item->value);
- X if (perform_actions(object->name,object->action,1) && !quitflag)
- X quit_xtpanel();
- X }
- }
- X
- void choice_update(object,value)
- Objdef *object;
- char *value;
- {
- X struct itemdef *item;
- X struct itemizedinfo *choice_info;
- X Arg arg[1];
- X int nitem;
- X
- X choice_info = object->info;
- X
- X /* loop over items - look for one that matches value and highlight */
- X for (item = choice_info->firstitem,nitem=0;
- X item != (struct itemdef*) 0; item=item->next,nitem++) {
- X if (!strcmp(item->value,value)) {
- X XawToggleUnsetCurrent(object->widgetname);
- X XtSetArg( arg[0], XtNstate, TRUE );
- X XtSetValues( item->widgetname, arg, ONE );
- X }
- X }
- }
- SHAR_EOF
- chmod 0664 xtpanel/choice.c ||
- echo 'restore of xtpanel/choice.c failed'
- Wc_c="`wc -c < 'xtpanel/choice.c'`"
- test 6770 -eq "$Wc_c" ||
- echo 'xtpanel/choice.c: original size 6770, current size' "$Wc_c"
- fi
- # ============= xtpanel/text.c ==============
- if test -f 'xtpanel/text.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/text.c (File already exists)'
- else
- echo 'x - extracting xtpanel/text.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/text.c' &&
- /*
- X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
- X * University. Official permission to use this software is included in
- X * the documentation. It authorizes you to use this file for any
- X * non-commercial purpose, provided that this copyright notice is not
- X * removed and that any modifications made to this file are commented
- X * and dated in the style of the example below.
- X */
- X
- /*
- X *
- X * source file: ./xtpanel/text.c
- X *
- X * Steve Cole, Dave Nichols (SEP), August 28 1992
- X * Inserted this sample edit history entry.
- X * Please log any further modifications made to this file:
- X * Steve Cole, Dave Nichols (SEP), November 20 1992 - version 2.00
- X * 1) added new objects: toggle, scrollbar, graph.
- X * 2) added new actions: ASSIGN, SET.
- X * 3) objects can have multiple actions.
- X * 4) backquoted strings in actions get executed at action time.
- X */
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- X
- #include <X11/Xaw/AsciiText.h>
- #include <X11/Xaw/Cardinals.h>
- #include <X11/Xaw/Text.h>
- X
- #include "object.h"
- #include "tree.h"
- #include "builders.h"
- X
- /* translation table used for text widget */
- char text_trans[] =
- X "<Leave>: update_text()";
- X
- void build_text(root,parent)
- X entry *root;
- X Widget parent;
- {
- X Objdef *object;
- X Arg args[20];
- X int narg;
- X Widget text;
- X char defname[8];
- X int width,height;
- X int numtext=1;
- X extern void text_update();
- X
- X /* create new object */
- X object = new_object();
- X
- X /* construct default dialog name */
- X sprintf(defname,"text%d",numtext++);
- X
- X /* find value, name, etc. in tree */
- X object->name = get_value(root,"name",defname);
- X object->action = parse_actions(object->name,root);
- X object->value = get_value(root,"value","");
- X width = (int) atoi(get_value(root,"width","500"));
- X height = (int) atoi(get_value(root,"height","100"));
- X
- X narg=0;
- X XtSetArg(args[narg], XtNscrollVertical, XawtextScrollWhenNeeded);
- X narg++;
- X XtSetArg(args[narg], XtNscrollHorizontal, XawtextScrollWhenNeeded);
- X narg++;
- X XtSetArg(args[narg], XtNwidth, width); narg++;
- X XtSetArg(args[narg], XtNheight, height); narg++;
- X XtSetArg(args[narg], XtNstring, object->value); narg++;
- X /* common parameters */
- X common_tags(root,args,&narg,SET_ALL);
- X
- X text = XtCreateManagedWidget(object->name,asciiTextWidgetClass,
- X parent,args,narg);
- X
- X object->widgetname = text;
- X object->updater = text_update;
- X
- X /* use translations to update value whenever mouse leaves widget */
- X XtAugmentTranslations(text,XtParseTranslationTable(text_trans));
- }
- X
- /*
- X * this routine gets called whenever we leave
- X * a text widget, to be sure its value is up to date
- X */
- void text_update_callback( w, event, params, num_params)
- X Widget w;
- X XEvent *event;
- X String *params;
- X Cardinal *num_params;
- {
- X Objdef* object;
- X char *value;
- X Arg args[10];
- X int narg;
- X
- X object = find_by_widget(w);
- X narg = 0;
- X XtSetArg(args[narg], XtNstring, &value); narg++;
- X XtGetValues(object->widgetname,args,narg);
- X object->value = strdupl(value);
- X perform_actions(object->name,object->action,1);
- }
- X
- void text_update(object,value)
- Objdef* object;
- char* value;
- {
- X Arg args[10];
- X int narg;
- X
- X narg = 0;
- X XtSetArg(args[narg], XtNstring, value); narg++;
- X XtSetValues(object->widgetname,args,narg);
- }
- SHAR_EOF
- chmod 0664 xtpanel/text.c ||
- echo 'restore of xtpanel/text.c failed'
- Wc_c="`wc -c < 'xtpanel/text.c'`"
- test 3373 -eq "$Wc_c" ||
- echo 'xtpanel/text.c: original size 3373, current size' "$Wc_c"
- fi
- # ============= xtpanel/variable.c ==============
- if test -f 'xtpanel/variable.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xtpanel/variable.c (File already exists)'
- else
- echo 'x - extracting xtpanel/variable.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/variable.c' &&
- /*
- X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
- X * University. Official permission to use this software is included in
- X * the documentation. It authorizes you to use this file for any
- X * non-commercial purpose, provided that this copyright notice is not
- X * removed and that any modifications made to this file are commented
- X * and dated in the style of the example below.
- X */
- X
- /*
- X *
- X * source file: ./xtpanel/variable.c
- X *
- X * Steve Cole, Dave Nichols (SEP), August 28 1992
- X * Inserted this sample edit history entry.
- X * Please log any further modifications made to this file:
- X * Steve Cole, Dave Nichols (SEP), November 20 1992 - version 2.00
- X * 1) added new objects: toggle, scrollbar, graph.
- X * 2) added new actions: ASSIGN, SET.
- X * 3) objects can have multiple actions.
- X * 4) backquoted strings in actions get executed at action time.
- X */
- X
- #include <X11/Intrinsic.h>
- X
- #include "object.h"
- #include "tree.h"
- #include "builders.h"
- X
- /* a variable has no screen representation it is just an object
- X * with a name and a value */
- void build_variable(root,parent)
- X entry *root;
- X Widget parent;
- {
- X Objdef *object;
- X char defname[12];
- X static int numvar=1;
- X
- X /* create new object */
- X object = new_object();
- X
- X /* construct default variable name */
- X sprintf(defname,"var%d",numvar++);
- X
- X /* find name, value */
- X object->name = get_value(root,"name",defname);
- X object->value = get_value(root,"value",object->name);
- X object->updater = 0; /* nothing to do */
- }
- SHAR_EOF
- chmod 0664 xtpanel/variable.c ||
- echo 'restore of xtpanel/variable.c failed'
- Wc_c="`wc -c < 'xtpanel/variable.c'`"
- test 1532 -eq "$Wc_c" ||
- echo 'xtpanel/variable.c: original size 1532, current size' "$Wc_c"
- fi
- true || echo 'restore of xtpanel/xtpanel.man.sed failed'
- echo End of part 6, continue with part 7
- exit 0
- -----------------------------------------------------------------
- Steve Cole (steve@sep.stanford.edu, apple!sep!steve)
- Department of Geophysics, Stanford University, Stanford, CA 94305
-