home *** CD-ROM | disk | FTP | other *** search
- 18-Jun-88 14:37:02-MDT,9931;000000000000
- Return-Path: <u-lchoqu%sunset@cs.utah.edu>
- Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:36:46 MDT
- Received: by cs.utah.edu (5.54/utah-2.0-cs)
- id AA22512; Sat, 18 Jun 88 14:36:43 MDT
- Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
- id AA24703; Sat, 18 Jun 88 14:36:40 MDT
- Date: Sat, 18 Jun 88 14:36:40 MDT
- From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
- Message-Id: <8806182036.AA24703@sunset.utah.edu>
- To: rthum@simtel20.arpa
- Subject: NumCaps.c.shar
-
- #! /bin/sh
- #
- # This is a shell archive. Save this into a file, edit it
- # and delete all lines above this comment. Then give this
- # file to sh by executing the command "sh file". The files
- # will be extracted into the current directory owned by
- # you with default permissions.
- #
- # The files contained herein are:
- #
- # 7 NumCaps.c
- # 1 NumCaps.r
- #
- echo 'Extracting NumCaps.c'
- if test -f NumCaps.c; then echo 'shar: will not overwrite NumCaps.c'; else
- cat << '________This_Is_The_END________' > NumCaps.c
- /* NumCaps.c
-
- DA to cut a character using its character code.
-
- Written by Jeffrey S. Shulman. Copyright 1985 Jeffrey S. Shulman
-
- Permission is hereby given to use any part of this code provided
- that this original copyright message remains intact and any changes,
- additions or modifcations are listed below and reported back to
- Jeffrey S. Shulman.
-
- Edit Date Who Comment
- 1.0 10/27/85 JSS Original Version
- */
-
- #include <stdio.h>
- #include <ctype.h>
- #include <desk.h>
- #include <acc.h>
- #include <file.h>
- #include <dialog.h>
- #include <event.h>
- #include <device.h>
- #include <scrap.h>
-
- /* Dialog ID's and items */
- #define NC_DIALOG 0
- #define COPY 1
- #define CLOSE 2
- #define CLEAR 3
- #define EDIT_TEXT 4
- #define FIRSTNUM 5
-
- ACC(0x2400, /* Responds to CNTRL call and call periodically */
- 0, /* Ticks between calls */
- 0x14A, /* Update, activate, mouse/key down */
- 0, /* No menu items */
- 7, "NumCaps") /* Length and text of title */
-
-
- /* The standard DA functions */
-
- accopen(dCtl, pb)
- dctlentry *dCtl;
- paramblockrec *pb;
- {
- DialogPtr d;
- int dNum, type;
- GrafPtr currPort;
- Rect r;
- Handle item;
-
- GetPort(&currPort); /* Save the current port */
- if (dCtl->dCtlWindow == NULL) { /* No dialog, create one */
- /* Compute the dialog number from our resource number */
- dNum = abs(dCtl->dCtlRefNum + 1);
- dNum = (32 * dNum) + NC_DIALOG - 16384;
- d = GetNewDialog(dNum, NULL, (long) -1);
- SetPort(d);
- /* Store away pertinent DA stuff */
- ((WindowPeek) d)->windowKind = dCtl->dCtlRefNum;
- dCtl->dCtlWindow = d;
- }
- SetPort(currPort); /* Restore the port */
- return 0;
- }
-
- accclose(dCtl, pb)
- dctlentry *dCtl;
- paramblockrec *pb;
- {
- DialogPtr d;
- GrafPtr currPort;
-
- GetPort(&currPort); /* Save the current port */
- d = dCtl->dCtlWindow;
- SetPort(d);
- dCtl->dCtlWindow = NULL;
- DisposDialog(d);
- SetPort(currPort); /* Restore the port */
- return 0;
- }
-
- accctl(dCtl, pb)
- dctlentry *dCtl;
- paramblockrec *pb;
- {
- GrafPtr currPort;
- DialogPtr d;
- int type;
- Handle item;
- Rect box;
-
- GetPort(&currPort); /* Save the current port */
- d = dCtl->dCtlWindow;
- SetPort(d);
- switch (pb->paramunion.CntrlParam.CSCode) {
- case accRun:
- doRun(dCtl, pb);
- case accEvent:
- doEvent(dCtl, pb);
- break;
- case accCut:
- case accCopy:
- doCopy(dCtl, pb, FALSE);
- break;
- case accPaste:
- doPaste(dCtl, pb);
- break;
- case accClear:
- GetDItem(d, EDIT_TEXT, &type, &item, &box);
- SetIText(item, "");
- InvalRect(&box); /* This has to be done to "clear" the box */
- break;
- }
- SetPort(currPort); /* Restore the port */
- return 0;
- }
-
- accprime()
- {
- }
-
- accstatus()
- {
- }
-
- /* This function handles a run call. Calls TEIdle to make the cursor
- blink */
- doRun(dCtl, pb)
- dctlentry *dCtl;
- paramblockrec *pb;
- {
- TEIdle(((DialogPeek) dCtl->dCtlWindow)->textH);
- }
-
- /* This function handles events */
- doEvent(dCtl, pb)
- dctlentry *dCtl;
- paramblockrec *pb;
- {
- EventRecord *eventPtr, event;
- DialogPtr d, dtemp;
- int oldWindowKind, itemHit, type;
- Handle item;
- Rect box;
- char ch, str[256];
- TEHandle TEH;
-
- d = dCtl->dCtlWindow;
- /* Temporarily change the windowKind to 2 for IsDialogEvent */
- oldWindowKind = ((WindowPeek) d)->windowKind;
- ((WindowPeek) d)->windowKind = 2;
- /* See if any events are ours */
- eventPtr = (EventRecord *) pb->paramunion.CntrlParam.csParam.diskBuff;
- if (IsDialogEvent(eventPtr)) {
- /* Handle keydown events ourselves */
- if (eventPtr->what == keyDown) {
- doKey(dCtl, pb, eventPtr);
- } else
- if (DialogSelect(eventPtr, &dtemp, &itemHit)) {
- /* We handle it */
- switch (itemHit) {
- case COPY:
- doCopy(dCtl, pb, TRUE);
- break;
- case CLOSE:
- CloseDeskAcc(dCtl->dCtlRefNum);
- break;
- case CLEAR:
- GetDItem(d, EDIT_TEXT, &type, &item, &box);
- SetIText(item, "");
- break;
- default:
- if (itemHit >= FIRSTNUM) {
- /* Must be one of the number keys */
- itemHit -= FIRSTNUM;
- if (itemHit > 9)
- ch = 'A' + itemHit - 10;
- else
- ch = '0' + itemHit;
- /* Allow only two characters total */
- GetDItem(d, EDIT_TEXT, &type, &item, &box);
- TEH = ((DialogPeek) dCtl->dCtlWindow)->textH;
- GetIText(item, &str);
- if ((strlen(str) < 2) ||
- ((*TEH)->selStart != (*TEH)->selEnd))
- TEKey(ch, TEH);
- else
- SysBeep(5);
- }
- }
- }
- }
- /* Restore the windowKind field */
- ((WindowPeek) d)->windowKind = oldWindowKind;
- }
-
- /* This function handles keydown events */
- doKey(dCtl, pb, eventPtr)
- dctlentry *dCtl;
- paramblockrec *pb;
- EventRecord *eventPtr;
- {
- DialogPtr d;
- char ch, str[256];
- int type;
- Handle item;
- Rect box;
- TEHandle TEH;
-
- d = dCtl->dCtlWindow;
- ch = eventPtr->message & charcodemask;
- if (islower(ch)) ch = _toupper(ch);
- /* Check for command keys */
- if ((eventPtr->modifiers & cmdKey) != 0) {
- switch (ch) {
- case 'C':
- case 'X':
- doCopy(dCtl, pb, FALSE);
- break;
- case 'V':
- doPaste(dCtl, pb);
- break;
- default:
- SysBeep(5);
- }
- return;
- }
- /* Check for valid characters and only allow a maximum of two */
- GetDItem(d, EDIT_TEXT, &type, &item, &box);
- GetIText(item, &str);
- TEH = ((DialogPeek) dCtl->dCtlWindow)->textH;
- if ((strlen(str) < 2) || ((*TEH)->selStart != (*TEH)->selEnd) ||
- (ch == '\b') || (ch == '\r') || (ch == '\03')) {
- if (((ch >= '0') && (ch <= '9')) ||
- ((ch >= 'A') && (ch <= 'F')) ||
- (ch == '\b')) {
- TEKey(ch, TEH);
- } else {
- if ((ch == '\r') || (ch == '\03')) /* Handle it as a COPY */
- doCopy(dCtl, pb, TRUE);
- else
- SysBeep(5);
- }
- } else
- SysBeep(5);
- }
-
- /* This function handles copying the char to the scrap. If close is TRUE
- then close us too if we cut something. */
- doCopy(dCtl, pb, close)
- dctlentry *dCtl;
- paramblockrec *pb;
- int close;
- {
- DialogPtr d;
- int type;
- Handle item;
- Rect box;
- char str[256];
- long num;
-
- d = dCtl->dCtlWindow;
- /* Make sure we have some chars to copy */
- GetDItem(d, EDIT_TEXT, &type, &item, &box);
- GetIText(item, &str);
- if (strlen(str) > 0) {
- num = strtol(str, (char **) NULL, 16);
- if (!ZeroScrap()) {
- str[0] = num & charcodemask;
- PutScrap((long) 1, "TEXT", str);
- if (close)
- CloseDeskAcc(dCtl->dCtlRefNum);
- }
- } else
- SysBeep(5);
- }
-
- /* This function handles Pasting */
- doPaste(dCtl, pb)
- dctlentry *dCtl;
- paramblockrec *pb;
- {
- Handle tHndl, item;
- long length, offset;
- char ch, buf[3];
- Rect box;
- int type;
- TEHandle TEH;
-
- tHndl = NewHandle(0L);
- length = GetScrap(tHndl, "TEXT", &offset);
- if (length > 0L) {
- ch = **tHndl;
- sprintf(buf, "%2x", ((unsigned) ch));
- GetDItem(dCtl->dCtlWindow, EDIT_TEXT, &type, &item, &box);
- SetIText(item, ""); /* Clear what is already there */
- /* "Type" the text in (for some reason SetIText doesn't display the text) */
- TEH = ((DialogPeek) dCtl->dCtlWindow)->textH;
- TEKey(buf[0], TEH);
- TEKey(buf[1], TEH);
- } else
- SysBeep(5);
- DisposHandle(tHndl);
- }
- ________This_Is_The_END________
- if test `wc -l < NumCaps.c` -ne 306; then
- echo 'shar: NumCaps.c was damaged during transit'
- echo ' (should have been 306 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting NumCaps.r'
- if test -f NumCaps.r; then echo 'shar: will not overwrite NumCaps.r'; else
- cat << '________This_Is_The_END________' > NumCaps.r
- * Resource file for NumCaps
-
- !NumCaps
- DFILDMOV
-
- * Version data and copyright
- Type JSS2 = STR
- ,-16000 (32)
- Numcaps 1.0 - October 27, 1985. Copyright 1985 Jeffrey S. Shulman
-
- * Dialogs
- Type DLOG
- ,-16000 (32)
- NumCaps
- 60 23 148 255
- inVisible NoGoAway
- 16
- 0
- -16000
-
- * Dialog Items
- Type DITL
- ,-16000 (32)
- 21
- BtnItem Enabled
- 36 186 75 223
- C & C
-
- BtnItem Enabled
- 57 109 81 174
- Close
-
- BtnItem Enabled
- 29 109 53 174
- Clear
-
- EditText Enabled
- 6 196 24 214
-
-
- BtnItem Enabled
- 5 5 22 25
- 0
-
- BtnItem Enabled
- 5 30 22 50
- 1
-
- BtnItem Enabled
- 5 55 22 75
- 2
-
- BtnItem Enabled
- 5 80 22 100
- 3
-
- BtnItem Enabled
- 25 5 42 25
- 4
-
- BtnItem Enabled
- 25 30 42 50
- 5
-
- BtnItem Enabled
- 25 55 42 75
- 6
-
- BtnItem Enabled
- 25 80 42 100
- 7
-
- BtnItem Enabled
- 45 5 62 25
- 8
-
- BtnItem Enabled
- 45 30 62 50
- 9
-
- BtnItem Enabled
- 45 55 62 75
- A
-
- BtnItem Enabled
- 45 80 62 100
- B
-
- BtnItem Enabled
- 65 5 82 25
- C
-
- BtnItem Enabled
- 65 30 82 50
- D
-
- BtnItem Enabled
- 65 55 82 75
- E
-
- BtnItem Enabled
- 65 80 82 100
- F
-
- StatText Disabled
- 7 110 23 180
- Char Code
-
-
- ________This_Is_The_END________
- if test `wc -l < NumCaps.r` -ne 109; then
- echo 'shar: NumCaps.r was damaged during transit'
- echo ' (should have been 109 bytes)'
- fi
- fi ; : end of overwriting check
- exit 0
-