home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / cshar_nu.sit < prev    next >
Encoding:
Text File  |  1988-06-20  |  9.3 KB  |  461 lines

  1. 18-Jun-88 14:37:02-MDT,9931;000000000000
  2. Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  3. Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:36:46 MDT
  4. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  5.     id AA22512; Sat, 18 Jun 88 14:36:43 MDT
  6. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  7.     id AA24703; Sat, 18 Jun 88 14:36:40 MDT
  8. Date: Sat, 18 Jun 88 14:36:40 MDT
  9. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  10. Message-Id: <8806182036.AA24703@sunset.utah.edu>
  11. To: rthum@simtel20.arpa
  12. Subject: NumCaps.c.shar
  13.  
  14. #! /bin/sh
  15. #
  16. # This is a shell archive.  Save this into a file, edit it
  17. # and delete all lines above this comment.  Then give this
  18. # file to sh by executing the command "sh file".  The files
  19. # will be extracted into the current directory owned by
  20. # you with default permissions.
  21. #
  22. # The files contained herein are:
  23. #
  24. #    7 NumCaps.c
  25. #    1 NumCaps.r
  26. #
  27. echo 'Extracting NumCaps.c'
  28. if test -f NumCaps.c; then echo 'shar: will not overwrite NumCaps.c'; else
  29. cat << '________This_Is_The_END________' > NumCaps.c
  30. /*     NumCaps.c
  31.  
  32.     DA to cut a character using its character code.
  33.  
  34.     Written by Jeffrey S. Shulman.  Copyright 1985  Jeffrey S. Shulman
  35.     
  36.     Permission is hereby given to use any part of this code provided
  37.     that this original copyright message remains intact and any changes,
  38.     additions or modifcations are listed below and reported back to
  39.     Jeffrey S. Shulman.
  40.     
  41.     Edit Date           Who    Comment
  42.     1.0    10/27/85      JSS    Original Version
  43. */
  44.  
  45. #include <stdio.h>
  46. #include <ctype.h>
  47. #include <desk.h>
  48. #include <acc.h>
  49. #include <file.h>
  50. #include <dialog.h>
  51. #include <event.h>
  52. #include <device.h>
  53. #include <scrap.h>
  54.  
  55. /* Dialog ID's and items */
  56. #define    NC_DIALOG    0
  57. #define COPY        1
  58. #define CLOSE        2
  59. #define    CLEAR        3
  60. #define EDIT_TEXT    4
  61. #define FIRSTNUM    5
  62.  
  63. ACC(0x2400,            /* Responds to CNTRL call and call periodically */
  64.     0,                /* Ticks between calls */
  65.     0x14A,            /* Update, activate, mouse/key down */
  66.     0,                /* No menu items */
  67.     7, "NumCaps")    /* Length and text of title */
  68.     
  69.  
  70. /* The standard DA functions */
  71.  
  72. accopen(dCtl, pb)
  73. dctlentry *dCtl;
  74. paramblockrec *pb;
  75. {
  76.     DialogPtr d;
  77.     int dNum, type;
  78.     GrafPtr currPort;
  79.     Rect r;
  80.     Handle item;
  81.     
  82.     GetPort(&currPort);                    /* Save the current port */
  83.     if (dCtl->dCtlWindow == NULL) {        /* No dialog, create one */
  84.         /* Compute the dialog number from our resource number */
  85.         dNum = abs(dCtl->dCtlRefNum + 1);
  86.         dNum = (32 * dNum) + NC_DIALOG - 16384;
  87.         d = GetNewDialog(dNum, NULL, (long) -1);
  88.         SetPort(d);
  89.         /* Store away pertinent DA stuff */
  90.         ((WindowPeek) d)->windowKind = dCtl->dCtlRefNum;
  91.         dCtl->dCtlWindow = d;
  92.     }
  93.     SetPort(currPort);                    /* Restore the port */
  94.     return 0;
  95. }
  96.  
  97. accclose(dCtl, pb)
  98. dctlentry *dCtl;
  99. paramblockrec *pb;
  100. {
  101.     DialogPtr d;
  102.     GrafPtr currPort;
  103.     
  104.     GetPort(&currPort);                    /* Save the current port */
  105.     d = dCtl->dCtlWindow;
  106.     SetPort(d);
  107.     dCtl->dCtlWindow = NULL;
  108.     DisposDialog(d);
  109.     SetPort(currPort);                    /* Restore the port */
  110.     return 0;
  111. }
  112.  
  113. accctl(dCtl, pb)
  114. dctlentry *dCtl;
  115. paramblockrec *pb;
  116. {
  117.     GrafPtr currPort;
  118.     DialogPtr d;
  119.     int type;
  120.     Handle item;
  121.     Rect box;
  122.  
  123.     GetPort(&currPort);                    /* Save the current port */
  124.     d = dCtl->dCtlWindow;
  125.     SetPort(d);
  126.     switch (pb->paramunion.CntrlParam.CSCode) {
  127.         case accRun:
  128.                 doRun(dCtl, pb);
  129.         case accEvent:
  130.                 doEvent(dCtl, pb);
  131.             break;
  132.         case accCut:
  133.         case accCopy:
  134.                 doCopy(dCtl, pb, FALSE);
  135.             break;
  136.         case accPaste:
  137.                 doPaste(dCtl, pb);
  138.             break;
  139.         case accClear:
  140.             GetDItem(d, EDIT_TEXT, &type, &item, &box);
  141.             SetIText(item, "");
  142.             InvalRect(&box);    /* This has to be done to "clear" the box */
  143.             break;
  144.     }
  145.     SetPort(currPort);                    /* Restore the port */
  146.     return 0;
  147. }
  148.  
  149. accprime()
  150. {
  151. }
  152.  
  153. accstatus()
  154. {
  155. }
  156.  
  157. /* This function handles a run call.  Calls TEIdle to make the cursor
  158.    blink */
  159. doRun(dCtl, pb)
  160. dctlentry *dCtl;
  161. paramblockrec *pb;
  162. {
  163.     TEIdle(((DialogPeek) dCtl->dCtlWindow)->textH);
  164. }
  165.  
  166. /* This function handles events */
  167. doEvent(dCtl, pb)
  168. dctlentry *dCtl;
  169. paramblockrec *pb;
  170. {
  171.     EventRecord *eventPtr, event;
  172.     DialogPtr d, dtemp;
  173.     int oldWindowKind, itemHit, type;
  174.     Handle item;
  175.     Rect box;
  176.     char ch, str[256];
  177.     TEHandle TEH;
  178.     
  179.     d = dCtl->dCtlWindow;
  180.     /* Temporarily change the windowKind to 2 for IsDialogEvent */
  181.     oldWindowKind = ((WindowPeek) d)->windowKind;
  182.     ((WindowPeek) d)->windowKind = 2;
  183.     /* See if any events are ours */
  184.     eventPtr = (EventRecord *) pb->paramunion.CntrlParam.csParam.diskBuff;
  185.     if (IsDialogEvent(eventPtr)) {
  186.         /* Handle keydown events ourselves */
  187.         if (eventPtr->what == keyDown) {
  188.             doKey(dCtl, pb, eventPtr);
  189.         } else 
  190.             if (DialogSelect(eventPtr, &dtemp, &itemHit)) {
  191.                 /* We handle it */
  192.                 switch (itemHit) {
  193.                     case COPY:
  194.                             doCopy(dCtl, pb, TRUE);
  195.                         break;
  196.                     case CLOSE:
  197.                         CloseDeskAcc(dCtl->dCtlRefNum);
  198.                         break;
  199.                     case CLEAR:
  200.                             GetDItem(d, EDIT_TEXT, &type, &item, &box);
  201.                             SetIText(item, "");
  202.                         break;
  203.                     default:
  204.                         if (itemHit >= FIRSTNUM) {
  205.                             /* Must be one of the number keys */
  206.                             itemHit -= FIRSTNUM;
  207.                             if (itemHit > 9)
  208.                                 ch = 'A' + itemHit - 10;
  209.                             else
  210.                                 ch = '0' + itemHit;
  211.                             /* Allow only two characters total */
  212.                             GetDItem(d, EDIT_TEXT, &type, &item, &box);
  213.                             TEH = ((DialogPeek) dCtl->dCtlWindow)->textH;
  214.                             GetIText(item, &str);
  215.                             if ((strlen(str) < 2) || 
  216.                                 ((*TEH)->selStart != (*TEH)->selEnd))
  217.                                 TEKey(ch, TEH);
  218.                             else
  219.                                 SysBeep(5);
  220.                         }
  221.                 }
  222.             }
  223.     }
  224.     /* Restore the windowKind field */
  225.     ((WindowPeek) d)->windowKind = oldWindowKind;
  226. }
  227.  
  228. /* This function handles keydown events */
  229. doKey(dCtl, pb, eventPtr)
  230. dctlentry *dCtl;
  231. paramblockrec *pb;
  232. EventRecord *eventPtr;
  233. {
  234.     DialogPtr d;
  235.     char ch, str[256];
  236.     int type;
  237.     Handle item;
  238.     Rect box;
  239.     TEHandle TEH;
  240.  
  241.     d = dCtl->dCtlWindow;
  242.     ch = eventPtr->message & charcodemask;
  243.     if (islower(ch)) ch = _toupper(ch);
  244.     /* Check for command keys */
  245.     if ((eventPtr->modifiers & cmdKey) != 0) {
  246.         switch (ch) {
  247.             case 'C':
  248.             case 'X':
  249.                 doCopy(dCtl, pb, FALSE);
  250.                 break;
  251.             case 'V':
  252.                 doPaste(dCtl, pb);
  253.                 break;
  254.             default:
  255.                 SysBeep(5);
  256.         }
  257.         return;
  258.     }
  259.     /* Check for valid characters and only allow a maximum of two */
  260.     GetDItem(d, EDIT_TEXT, &type, &item, &box);
  261.     GetIText(item, &str);
  262.     TEH = ((DialogPeek) dCtl->dCtlWindow)->textH;
  263.     if ((strlen(str) < 2) || ((*TEH)->selStart != (*TEH)->selEnd) ||
  264.         (ch == '\b') || (ch == '\r') || (ch == '\03')) {
  265.             if (((ch >= '0') && (ch <= '9')) ||
  266.                 ((ch >= 'A') && (ch <= 'F')) ||
  267.                 (ch == '\b')) {
  268.                     TEKey(ch, TEH);
  269.             } else {
  270.                 if ((ch == '\r') || (ch == '\03')) /* Handle it as a COPY */
  271.                     doCopy(dCtl, pb, TRUE);
  272.                 else
  273.                     SysBeep(5);
  274.             }
  275.     } else
  276.         SysBeep(5);
  277. }
  278.  
  279. /* This function handles copying the char to the scrap.  If close is TRUE
  280.    then close us too if we cut something. */
  281. doCopy(dCtl, pb, close)
  282. dctlentry *dCtl;
  283. paramblockrec *pb;
  284. int close;
  285. {
  286.     DialogPtr d;
  287.     int type;
  288.     Handle item;
  289.     Rect box;
  290.     char str[256];
  291.     long num;
  292.  
  293.     d = dCtl->dCtlWindow;
  294.     /* Make sure we have some chars to copy */
  295.     GetDItem(d, EDIT_TEXT, &type, &item, &box);
  296.     GetIText(item, &str);
  297.     if (strlen(str) > 0) {
  298.         num = strtol(str, (char **) NULL, 16);
  299.         if (!ZeroScrap()) {
  300.             str[0] = num & charcodemask;
  301.             PutScrap((long) 1, "TEXT", str);
  302.             if (close)
  303.                 CloseDeskAcc(dCtl->dCtlRefNum);
  304.         }
  305.     } else
  306.         SysBeep(5);
  307. }
  308.  
  309. /* This function handles Pasting */
  310. doPaste(dCtl, pb)
  311. dctlentry *dCtl;
  312. paramblockrec *pb;
  313. {
  314.     Handle tHndl, item;
  315.     long length, offset;
  316.     char ch, buf[3];
  317.     Rect box;
  318.     int type;
  319.     TEHandle TEH;
  320.     
  321.     tHndl = NewHandle(0L);
  322.     length = GetScrap(tHndl, "TEXT", &offset);
  323.     if (length > 0L) {
  324.         ch = **tHndl;
  325.         sprintf(buf, "%2x", ((unsigned) ch));
  326.         GetDItem(dCtl->dCtlWindow, EDIT_TEXT, &type, &item, &box);
  327.         SetIText(item, "");            /* Clear what is already there */
  328.         /* "Type" the text in (for some reason SetIText doesn't display the text) */
  329.         TEH = ((DialogPeek) dCtl->dCtlWindow)->textH;
  330.         TEKey(buf[0], TEH);
  331.         TEKey(buf[1], TEH);
  332.     } else
  333.         SysBeep(5);
  334.     DisposHandle(tHndl);
  335. }
  336. ________This_Is_The_END________
  337. if test `wc -l < NumCaps.c` -ne 306; then
  338.     echo 'shar: NumCaps.c was damaged during transit'
  339.   echo '      (should have been 306 bytes)'
  340. fi
  341. fi        ; : end of overwriting check
  342. echo 'Extracting NumCaps.r'
  343. if test -f NumCaps.r; then echo 'shar: will not overwrite NumCaps.r'; else
  344. cat << '________This_Is_The_END________' > NumCaps.r
  345. * Resource file for NumCaps
  346.  
  347. !NumCaps
  348. DFILDMOV
  349.  
  350. * Version data and copyright
  351. Type JSS2 = STR 
  352.     ,-16000 (32)
  353.     Numcaps 1.0 - October 27, 1985. Copyright 1985 Jeffrey S. Shulman
  354.  
  355. * Dialogs
  356. Type DLOG
  357.     ,-16000    (32)    
  358. NumCaps
  359. 60 23 148 255 
  360. inVisible NoGoAway 
  361. 16
  362. 0
  363. -16000                
  364.  
  365. * Dialog Items
  366. Type DITL
  367.     ,-16000 (32)
  368. 21
  369. BtnItem Enabled
  370. 36 186 75 223 
  371. C & C
  372.  
  373. BtnItem Enabled
  374. 57 109 81 174 
  375. Close
  376.  
  377. BtnItem Enabled
  378. 29 109 53 174 
  379. Clear
  380.  
  381. EditText Enabled
  382. 6 196 24 214 
  383.  
  384.  
  385. BtnItem Enabled
  386. 5 5 22 25 
  387. 0
  388.  
  389. BtnItem Enabled
  390. 5 30 22 50 
  391. 1
  392.  
  393. BtnItem Enabled
  394. 5 55 22 75 
  395. 2
  396.  
  397. BtnItem Enabled
  398. 5 80 22 100 
  399. 3
  400.  
  401. BtnItem Enabled
  402. 25 5 42 25 
  403. 4
  404.  
  405. BtnItem Enabled
  406. 25 30 42 50 
  407. 5
  408.  
  409. BtnItem Enabled
  410. 25 55 42 75 
  411. 6
  412.  
  413. BtnItem Enabled
  414. 25 80 42 100 
  415. 7
  416.  
  417. BtnItem Enabled
  418. 45 5 62 25 
  419. 8
  420.  
  421. BtnItem Enabled
  422. 45 30 62 50 
  423. 9
  424.  
  425. BtnItem Enabled
  426. 45 55 62 75 
  427. A
  428.  
  429. BtnItem Enabled
  430. 45 80 62 100 
  431. B
  432.  
  433. BtnItem Enabled
  434. 65 5 82 25 
  435. C
  436.  
  437. BtnItem Enabled
  438. 65 30 82 50 
  439. D
  440.  
  441. BtnItem Enabled
  442. 65 55 82 75 
  443. E
  444.  
  445. BtnItem Enabled
  446. 65 80 82 100 
  447. F
  448.  
  449. StatText Disabled
  450. 7 110 23 180 
  451. Char Code
  452.  
  453.  
  454. ________This_Is_The_END________
  455. if test `wc -l < NumCaps.r` -ne 109; then
  456.     echo 'shar: NumCaps.r was damaged during transit'
  457.   echo '      (should have been 109 bytes)'
  458. fi
  459. fi        ; : end of overwriting check
  460. exit 0
  461.