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

  1. 18-Jun-88 14:39:29-MDT,24316;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:38:56 MDT
  4. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  5.     id AA22548; Sat, 18 Jun 88 14:38:50 MDT
  6. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  7.     id AA24727; Sat, 18 Jun 88 14:38:46 MDT
  8. Date: Sat, 18 Jun 88 14:38:46 MDT
  9. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  10. Message-Id: <8806182038.AA24727@sunset.utah.edu>
  11. To: rthum@simtel20.arpa
  12. Subject: QuicKeys.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. # These code resources all interact with CE Software's QuicKeys
  23. # keyboard enhancer.
  24. # The files contained herein are:
  25. #
  26. #    5 GotoStdfile.c
  27. #    4 ProjectSwitch.c
  28. #    8 SetQuicText.c
  29. #    5 quickeys.h
  30. #
  31. echo 'Extracting GotoStdfile.c'
  32. if test -f GotoStdfile.c; then echo 'shar: will not overwrite GotoStdfile.c'; else
  33. sed 's/^X//' << '________This_Is_The_END________' > GotoStdfile.c
  34. X/*
  35. X  * StdFile:        XCMD to position the standard file open dialog box to a particular volume & folder.
  36. X  *                Can also be built as an FKEY for use in a QuicKeys environment, where it takes its
  37. X  *                argument from a text key (Command-Option-Shift-Zero).
  38. X  *                Dewi Williams, Delphi: DEWI.
  39. X  */
  40. X
  41. X#include    <MemoryMgr.h>
  42. X#include    <EventMgr.h>
  43. X#include    <FileMgr.h>
  44. X#include    <HFS.h>
  45. X#include    <StdFilePkg.h>
  46. X#include    <HyperXCmd.h>            /* Defines and structures for HyperCard XCMD programming */
  47. X#include    "QuicKeys.h"
  48. X
  49. X/* Build a FKEY instead of a Hypercard XCMD. */
  50. X#define    FKEY     1
  51. X#define    NULL        0L
  52. X
  53. X/* Forward references */
  54. XQuicInitBlock    *FindSysHeap();
  55. XStringPtr        pstrchr(StringPtr str, unsigned char c);
  56. XBoolean        FindSFArg(QuicInitBlock *qb, StringPtr arg);
  57. X
  58. Xpascal void
  59. Xmain(paramPtr)
  60. X#ifndef    FKEY
  61. XXCmdBlockPtr    paramPtr;
  62. X#endif
  63. X{
  64. X    DirInfo                dirInfo;
  65. X    HVolumeParam            v;
  66. X    register unsigned char     *partialPath;
  67. X    register Byte            slen;
  68. X    Str255                pathName;
  69. X    QuicInitBlock            *qb;
  70. X
  71. X    /* Check for HFS */
  72. X    if (FSFCBLen == -1) {                        /* Not running HFS */
  73. X        SysBeep(1);
  74. X        return;
  75. X    }
  76. X
  77. X#ifdef    FKEY
  78. X    /* Retrieve the path. It's to be found as a program-specific text item (Cmd-Option-Shift-0 (zero)). */
  79. X    if ( (qb = FindSysHeap()) == NULL) {
  80. X        SysBeep(1);
  81. X        return;
  82. X    }
  83. X
  84. X    if (FindSFArg(qb, pathName) == FALSE) {
  85. X        /* Keycode doesn't exist. */
  86. X        SysBeep(1);
  87. X        return;
  88. X    }
  89. X#else
  90. X    /* There should only be one parameter. */
  91. X    if (paramPtr->paramCount != 1) {
  92. X        SysBeep(1);
  93. X        return;
  94. X    }
  95. X
  96. X    /* First param is the pathname.  Convert it to a pascal string */
  97. X    ZeroToPas(paramPtr,*(paramPtr->params[0]), pathName);
  98. X#endif
  99. X
  100. X    /* The path  must contain at least 1 colon. */
  101. X    if ((partialPath = pstrchr(pathName, ':')) == NULL) {
  102. X        SysBeep(1);
  103. X        return;
  104. X    }
  105. X
  106. X    /* Temporarily isolate the volume component of the pathname. */
  107. X    slen = pathName[0];                            /* Save the length */
  108. X    pathName[0] = (long)partialPath - (long)pathName;
  109. X
  110. X    /* First, get the vRefNum corresponding to Programming: */
  111. X    v.ioCompletion = NULL;
  112. X    v.ioNamePtr = pathName;
  113. X    v.ioVRefNum = 0x8000;        /* See TechNote #77 */
  114. X    v.ioVolIndex = -1;             /* use name & vrefnum */
  115. X    
  116. X    if (PBHGetVInfo(&v, FALSE) != noErr) {
  117. X        SysBeep(1);
  118. X        return;
  119. X    }
  120. X
  121. X    pathName[0] = slen;            /* Restore the full path */
  122. X
  123. X    /* Now we need the dirID corresponding to the partial path. */
  124. X    dirInfo.ioCompletion = NULL;
  125. X    dirInfo.ioNamePtr = pathName;
  126. X    dirInfo.ioVRefNum = 0;
  127. X    dirInfo.ioFDirIndex = 0;        /* use name and vrefnum */
  128. X    dirInfo.ioDrDirID = 0;
  129. X
  130. X    if (PBGetCatInfo(&dirInfo, FALSE) != noErr) {
  131. X        SysBeep(1);
  132. X        return;
  133. X    }
  134. X
  135. X    /* And is it a folder? */
  136. X    if ( ! (dirInfo.ioFlAttrib & 0x10 )) {        /* It's a file! */
  137. X        SysBeep(1);
  138. X        return;
  139. X    }
  140. X
  141. X    /* Set up the folder info for StdFile. */
  142. X    CurDirStore = dirInfo.ioDrDirID;
  143. X
  144. X    /* Set up the volume info for StdFile. */
  145. X    SFSaveDisk = -1 * v.ioVRefNum;
  146. X}
  147. X
  148. X/*
  149. X  * pstrchr:        return pointer to first occurrence of char in pstring.
  150. X  */
  151. X
  152. XStringPtr
  153. Xpstrchr(str, c)
  154. Xregister StringPtr        str;
  155. Xregister unsigned char    c;
  156. X{
  157. X    register StringPtr    end = str + str[0] + 1;
  158. X    
  159. X    for (str++;str < end; str++)
  160. X        if (*str == c) return str;
  161. X
  162. X    return NULL;
  163. X}
  164. X
  165. X#ifdef FKEY
  166. X/*
  167. X  * This is a  C version of the example code in Chapter 8 of the QuicKeys manual.
  168. X  */
  169. X
  170. XQuicInitBlock *
  171. XFindSysHeap()
  172. X{
  173. X    register Ptr            endBlk = SysZone->bkLim;
  174. X    register QuicInitBlock    *qp;
  175. X    
  176. X    qp = (QuicInitBlock *) &SysZone->heapData;
  177. X
  178. X    while(qp != (QuicInitBlock *) endBlk) {
  179. X        /* Analyze the block we're looking at. */
  180. X        if ((qp->header[0] & 0xC0) == 0x40) {                /* Is it non-relocatable? */
  181. X            /* Check magic and signature. */
  182. X            if (qp->quic.magic == 0xa89f1234 && qp->quic.signature == 'CELN') {
  183. X                /* Chapter 8 states that the version number is 1. It's actually 0 (as the example
  184. X                  * assembly language shows and a quick call to CE Software confirmed).
  185. X                  */
  186. X                if (qp->quic.version == 0) return qp;
  187. X            }
  188. X        }
  189. X
  190. X        /* Time to move on to the next block. The 0xFFFFFF strips off the tag byte(s). */
  191. X        qp = (QuicInitBlock *)(((Byte *)qp) + ((* (long *)&qp->header) & 0xFFFFFF));
  192. X    }
  193. X    return NULL;        /* Failed to find it */
  194. X}
  195. X
  196. X/*
  197. X  *    FindSFArg:    Hunts for current contents of Cmd-Option-Shift-Zero.
  198. X  */
  199. X
  200. XBoolean
  201. XFindSFArg(qb, arg)
  202. XQuicInitBlock    *qb;
  203. XStringPtr        arg;
  204. X{
  205. X    register KeyRecord    *kr = qb->quic.application;
  206. X    register KeyRecord    *end = kr + N_QCKEYS;
  207. X
  208. X    /* 0x1de2 is the keycode/charcode for Cmd-Option-Shift-0 (found by experimentation). */
  209. X    for (; kr < end; kr++) {
  210. X        if (kr->QKtype == QK_TEXT) {
  211. X            if ((kr->key) == 0x1de2 && (kr->modifiers == (cmdKey|optionKey|shiftKey))) {
  212. X                BlockMove(kr->u.QuicText.text, arg, (Size)(kr->u.QuicText.text[0] +1));
  213. X                return TRUE;
  214. X            }
  215. X        }
  216. X    }
  217. X    return FALSE;
  218. X}
  219. X#endif
  220. ________This_Is_The_END________
  221. if test `wc -l < GotoStdfile.c` -ne 186; then
  222.     echo 'shar: GotoStdfile.c was damaged during transit'
  223.   echo '      (should have been 186 bytes)'
  224. fi
  225. fi        ; : end of overwriting check
  226. echo 'Extracting ProjectSwitch.c'
  227. if test -f ProjectSwitch.c; then echo 'shar: will not overwrite ProjectSwitch.c'; else
  228. sed 's/^X//' << '________This_Is_The_END________' > ProjectSwitch.c
  229. X/*
  230. X  * ProjectSwitch:        FKEY that works with QuicKeys to automate project switching for multiple project
  231. X  *                    environments. It puts the name of the current project into a QuicKey text key.
  232. X  *                    This can be used as a form of parameter substitution for sequences.
  233. X  *                    The key chosen is Cmd-Option-Shift 1.
  234. X  */
  235. X
  236. X
  237. X#include    <MacTypes.h>
  238. X#include    <MemoryMgr.h>
  239. X#include    <EventMgr.h>
  240. X#include    <WindowMgr.h>
  241. X#include    <SegmentLdr.h>
  242. X#include    "QuicKeys.h"
  243. X
  244. X#define    NULL        0L
  245. X
  246. X/* Forward references */
  247. XQuicInitBlock    *FindSysHeap();
  248. XBoolean        UpdateParamKey(QuicInitBlock *qb, StringHandle theText, int param);
  249. X
  250. Xpascal void
  251. Xmain()
  252. X{
  253. X    register WindowPeek        wp;
  254. X    register QuicInitBlock     *qb;
  255. X
  256. X    /* Have to be running Lightspeed C */
  257. X    if (IUCompString(CurApName, "\pLightspeedC\252") != 0) {
  258. X        SysBeep(1);
  259. X        return;
  260. X    }
  261. X
  262. X    if ((qb = FindSysHeap()) == NULL) {
  263. X        SysBeep(1);
  264. X        return;
  265. X    }
  266. X
  267. X    /*
  268. X      * Search the window list for the project window. This search relies on Lightspeed C internals
  269. X      * deduced via TMON - namely: document windows have a windowKind of 0xB, and the project
  270. X      * window has one of 0xA.
  271. X      */
  272. X    for (wp = WindowList; wp != NULL; wp = wp->nextWindow) {
  273. X        if (wp->windowKind == 0xA) {                /* A project window */
  274. X            /* wp->titleHandle is a StringHandle to the window title. This corresponds to the
  275. X              * project name. So we search for the reserved key record (type QK_TEXT,
  276. X              * key 1, modifiers (Cmd,Option,Shift). When found, we copy in the required
  277. X              * title.
  278. X              */
  279. X            if (UpdateParamKey(qb, wp->titleHandle, 1) == FALSE) SysBeep(1);
  280. X            return;
  281. X        }
  282. X    }
  283. X}
  284. X
  285. X
  286. X/*
  287. X  * This is a  C version of the example code in Chapter 8 of the QuicKeys manual.
  288. X  */
  289. X
  290. XQuicInitBlock *
  291. XFindSysHeap()
  292. X{
  293. X    register Ptr            endBlk = SysZone->bkLim;
  294. X    register QuicInitBlock    *qp;
  295. X    
  296. X    qp = (QuicInitBlock *) &SysZone->heapData;
  297. X
  298. X    while(qp != (QuicInitBlock *) endBlk) {
  299. X        /* Analyze the block we're looking at. */
  300. X        if ((qp->header[0] & 0xC0) == 0x40) {                /* Is it non-relocatable? */
  301. X            /* Check magic and signature. */
  302. X            if (qp->quic.magic == 0xa89f1234 && qp->quic.signature == 'CELN') {
  303. X                /* Chapter 8 states that the version number is 1. It's actually 0 (as the example
  304. X                  * assembly language shows and a quick call to CE Software confirmed).
  305. X                  */
  306. X                if (qp->quic.version == 0) return qp;
  307. X            }
  308. X        }
  309. X
  310. X        /* Time to move on to the next block. The 0xFFFFFF strips off the tag byte(s). */
  311. X        qp = (QuicInitBlock *)(((Byte *)qp) + ((* (long *)&qp->header) & 0xFFFFFF));
  312. X    }
  313. X    return NULL;        /* Failed to find it */
  314. X}
  315. X
  316. X/*
  317. X  * Cmd-Shift-Option 1 through 4 are reserved as parameter records of type 'text' (prog-specific).
  318. X  * This routine searches for the given record and copies in the text.
  319. X  */
  320. X
  321. XBoolean
  322. XUpdateParamKey(qb, theText, param)
  323. XQuicInitBlock    *qb;
  324. XStringHandle    theText;
  325. Xint            param;
  326. X{
  327. X    register KeyRecord    *kr = qb->quic.application;
  328. X    register KeyRecord    *end = kr + N_QCKEYS;
  329. X    register unsigned    key;
  330. X
  331. X    /* This depends on the fact that keys 1 through 4 have consecutive keycode values. The charcode values
  332. X      * were found by experimentation.
  333. X      */
  334. X    key = ((0x11 + param) << 8) + 0xD9 + param;        /* Convert to keycode & charcode */
  335. X
  336. X    for (; kr < end; kr++) {
  337. X        if (kr->QKtype == QK_TEXT) {
  338. X            if ((kr->key) == key && (kr->modifiers == (cmdKey|optionKey|shiftKey))) {
  339. X                BlockMove(*theText, kr->u.QuicText.text, (Size)((*theText)[0] + 1));
  340. X                return TRUE;
  341. X            }
  342. X        }
  343. X    }
  344. X    return FALSE;
  345. X}
  346. ________This_Is_The_END________
  347. if test `wc -l < ProjectSwitch.c` -ne 117; then
  348.     echo 'shar: ProjectSwitch.c was damaged during transit'
  349.   echo '      (should have been 117 bytes)'
  350. fi
  351. fi        ; : end of overwriting check
  352. echo 'Extracting SetQuicText.c'
  353. if test -f SetQuicText.c; then echo 'shar: will not overwrite SetQuicText.c'; else
  354. sed 's/^X//' << '________This_Is_The_END________' > SetQuicText.c
  355. X/*
  356. X  * SetQuicText:        Hypercard XCMD to set up a text QuicKey with a text string of up to 72 characters.
  357. X  *                    Usage:  SetQuicText modifiers, virtual key, text
  358. X  *                    Modifiers can be one or more of "C" (Command), "L" (CapsLock), "O" (Option),
  359. X  *                    "c" (Control), and "S" (Shift).
  360. X  *                    The virtual key is a hardware-independent method of identifying a key. There's a
  361. X  *                    table of key/char equivalences in Inside Macintosh Volume V, and also in the stack
  362. X  *                    distributed with the PostEvent XCMD.
  363. X  *                    Note that the text key has to be defined before this XCMD is run - i.e. the slot has
  364. X  *                    to be reserved, and is assumed to be universal rather than program-specific (the
  365. X  *                    XCMD looks at both, but checks universal first).
  366. X  *                    Dewi Williams. Delphi: Dewi.
  367. X  */
  368. X
  369. X#include    <MemoryMgr.h>
  370. X#include    <EventMgr.h>
  371. X#include    <HyperXCmd.h>            /* Defines and structures for HyperCard XCMD programming */
  372. X#include    <Environs.h>            /* Defines for the SysEnvirons trap */
  373. X#include    <ScriptMgr.h>            /* Came with the 2.11 upgrade as "xScriptMgr.h" */
  374. X#include    "QuicKeys.h"            /* Defines and structures for QuicKeys internals access */
  375. X
  376. X#define    NULL        0L
  377. X#define    HiWord(x)        (((unsigned short *)&(x))[0])
  378. X#define    LoWord(x)        (((unsigned short *)&(x))[1])
  379. X#define    controlKey    4096
  380. X
  381. X/* Forward references */
  382. XQuicInitBlock    *FindSysHeap();
  383. Xint            CalcModifiers(StringPtr str);
  384. Xint            CalculateCharCode(int modifiers, int theKey);
  385. XBoolean        UpdateKeySlot(QuicInitBlock *qb, int kcode, int modifiers, StringPtr text);
  386. X
  387. Xpascal void
  388. Xmain(paramPtr)
  389. XXCmdBlockPtr    paramPtr;
  390. X{
  391. X    Str255            text;
  392. X    QuicInitBlock        *qb;
  393. X    int                theKey;
  394. X    int                 modifiers;
  395. X    SysEnvRec        env;
  396. X    int                kcode;
  397. X
  398. X    /* Ensure that this is system 4.1 or later.  This is needed for KeyTrans and extended keyboard
  399. X      * checks. It ensures that KCHR/KMAP keyboard mappings are in place.
  400. X      */
  401. X    if (SysEnvirons(1, &env) == envNotPresent) {
  402. X        /* We beep rather than put up an error message because I don't like hardwiring English
  403. X          * strings into programs, and haven't figured out an owned resource type of technique for
  404. X          * putting the error messages into resources. Apple needs to set a standard here (minor editorial!).
  405. X          */
  406. X        SysBeep(1);
  407. X        return;
  408. X    }
  409. X
  410. X    /* There should be 3 parameters. */
  411. X    if (paramPtr->paramCount != 3) {
  412. X        SysBeep(1);
  413. X        return;
  414. X    }
  415. X
  416. X    /* Find QuicKeys in the system heap. */
  417. X    if ( (qb = FindSysHeap()) == NULL) {
  418. X        /* Not running QuicKeys */
  419. X        SysBeep(1);
  420. X        return;
  421. X    }
  422. X
  423. X    /* First param is the modifiers.  Convert it to a pascal string */
  424. X    ZeroToPas(paramPtr,*(paramPtr->params[0]), text);
  425. X    
  426. X    modifiers = CalcModifiers(text);
  427. X
  428. X    /* If the control key is specified, see if this is possible with the current keyboard. */
  429. X    if (modifiers&controlKey) {
  430. X        /* Make no assumptions about new keyboard models! */
  431. X        if (env.keyBoardType <= envStandADBKbd && env.keyBoardType != envAExtendKbd) {
  432. X            SysBeep(1);
  433. X            return;
  434. X        }
  435. X    }
  436. X
  437. X    /* The second param is the virtual keycode.  */
  438. X    ZeroToPas(paramPtr,*(paramPtr->params[1]), text);
  439. X    theKey = ((int)StrToNum(paramPtr, (Str31 *)text)) & 0x7F;
  440. X
  441. X    /* Sanity check: virtual keycodes past 0x60 belong to the extended keyboard (function keys, PageUp
  442. X      * etc. To stop any possible confusion, we check for the existence of the extended keyboard before
  443. X      * posting any such event.
  444. X      */
  445. X    if (theKey > 0x60 && env.keyBoardType != envAExtendKbd) {
  446. X        SysBeep(1);
  447. X        return;
  448. X    }
  449. X
  450. X    /* Third parameter is the text to substitute. */
  451. X    ZeroToPas(paramPtr,*(paramPtr->params[2]), text);
  452. X
  453. X    /* Clamp the string if it's too big. */
  454. X    if (text[0] > 71) text[0] = 71;            /* with room for the length byte */
  455. X    
  456. X    if ( (kcode = CalculateCharCode(modifiers, theKey)) == 0) {
  457. X        /* Bad virtual keycode? */
  458. X        SysBeep(1);
  459. X        return;
  460. X    }
  461. X
  462. X    if (UpdateKeySlot(qb, kcode, modifiers, text) == FALSE) {
  463. X        /* Slot wasn't reserved in universal key area. */
  464. X        SysBeep(1);
  465. X    }
  466. X}
  467. X
  468. X/*
  469. X  * This is a  C version of the example code in Chapter 8 of the QuicKeys manual.
  470. X  */
  471. X
  472. XQuicInitBlock *
  473. XFindSysHeap()
  474. X{
  475. X    register Ptr            endBlk = SysZone->bkLim;
  476. X    register QuicInitBlock    *qp;
  477. X    
  478. X    qp = (QuicInitBlock *) &SysZone->heapData;
  479. X
  480. X    while(qp != (QuicInitBlock *) endBlk) {
  481. X        /* Analyze the block we're looking at. */
  482. X        if ((qp->header[0] & 0xC0) == 0x40) {                /* Is it non-relocatable? */
  483. X            /* Check magic and signature. */
  484. X            if (qp->quic.magic == 0xa89f1234 && qp->quic.signature == 'CELN') {
  485. X                /* Chapter 8 states that the version number is 1. It's actually 0 (as the example
  486. X                  * assembly language shows and a quick call to CE Software confirmed).
  487. X                  */
  488. X                if (qp->quic.version == 0) return qp;
  489. X            }
  490. X        }
  491. X
  492. X        /* Time to move on to the next block. The 0xFFFFFF strips off the tag byte(s). */
  493. X        qp = (QuicInitBlock *)(((Byte *)qp) + ((* (long *)&qp->header) & 0xFFFFFF));
  494. X    }
  495. X    return NULL;        /* Failed to find it */
  496. X}
  497. X
  498. X/*
  499. X  * CalculateCharCode:    given a virtual keycode value, calculate the keycode/charcode combination.
  500. X  */
  501. X
  502. Xint
  503. XCalculateCharCode(modifiers, theKey)
  504. Xint         modifiers;
  505. Xint        theKey;
  506. X{
  507. X    long                kResult;
  508. X    long                state = 0;
  509. X    Handle            hKeyData;
  510. X    register int        kchrID;
  511. X    int            theCode;
  512. X
  513. X    /* Calculate the resource ID of the relevant KCHR resource. The Script Manager has
  514. X      * this information. This may be useful if you're using Dvorak mappings, for instance.
  515. X      * I haven't really been able to test this - 0 is the US default, and it's the only one I
  516. X      * have.
  517. X      */
  518. X    kchrID = (int)GetScript(GetEnvirons(smKeyScript), smScriptKeys);
  519. X
  520. X    if ( (hKeyData = GetResource('KCHR', kchrID)) == NULL) {
  521. X        /* We've confirmed that it is System 4.1 or later. Strange. */
  522. X        SysBeep(1);
  523. X        return;
  524. X    }
  525. X
  526. X    /* The keyCode parameter passed to the KeyTrans trap consists of the modifier
  527. X      * flags in bits 8-15, up/down stroke in bit 7 (1 = up), and the virtual key
  528. X      * code in bits 6 - 0. 
  529. X      */
  530. X    modifiers |= btnState;                    /* The mouse button is UP */
  531. X    theKey |= modifiers;                        /* Already in bits 8-15 */
  532. X
  533. X    /* I'm assuming here that KeyTrans doesn't move the heap. Don't see why it should. */
  534. X    if ( (kResult = KeyTrans(*hKeyData, theKey, &state)) == 0) return 0;
  535. X
  536. X    /* kResult consists of 2 16 bit characters to be posted as events (usually the high word of each is 0),
  537. X      * high word first. A return value of 0 in either word should not be posted. 
  538. X      */
  539. X    if ((theCode = HiWord(kResult)) != 0) {
  540. X        if (LoWord(kResult) != 0) {
  541. X            /* This combination's inappropriate - it has to be a single keycode/charcode combination.  */
  542. X            return 0;
  543. X        }
  544. X    } else {
  545. X        theCode = LoWord(kResult);
  546. X    }
  547. X
  548. X    theKey &= 0x7F;            /* Cut out any modifiers */
  549. X    theKey <<= 8;                /* And shift to the keyCode position */
  550. X    theCode |= theKey;
  551. X
  552. X    return theCode;
  553. X}
  554. X
  555. X/* Convert the modifier string to its numeric equivalent. This code isn't perfect - it does
  556. X  * blind matches without validating for odd characters. For instance "LXO" == "LO".
  557. X  */
  558. X
  559. Xstatic int
  560. XCalcModifiers(str)
  561. Xregister StringPtr    str;
  562. X{
  563. X    register StringPtr    end = str + str[0] + 1;
  564. X    register int    modifiers =  0;
  565. X
  566. X    for (str++;str < end; str++) {
  567. X        switch( (*str) ) {
  568. X        case 'C':
  569. X            modifiers |= cmdKey;
  570. X            break;
  571. X        case 'S':
  572. X            modifiers |= shiftKey;
  573. X            break;
  574. X        case 'L':
  575. X            modifiers |= alphaLock;
  576. X            break;
  577. X        case 'O':
  578. X            modifiers |= optionKey;
  579. X            break;
  580. X        case 'c':
  581. X            modifiers |= controlKey;
  582. X            break;
  583. X        }
  584. X    }
  585. X    return modifiers;
  586. X}
  587. X
  588. X/*
  589. X  * Write "theText" into the QuicKeys text key slot identified by "kcode". Look in universal first, then
  590. X  * in program-specific.
  591. X  */
  592. X
  593. XBoolean
  594. XUpdateKeySlot(qb, kcode, modifiers, theText)
  595. XQuicInitBlock    *qb;
  596. Xint            kcode;
  597. Xint            modifiers;
  598. XStringPtr        theText;
  599. X{
  600. X    register KeyRecord    *kr = qb->quic.universal;
  601. X    register KeyRecord    *end = kr + N_QCKEYS;
  602. X
  603. X    for (; kr < end; kr++) {
  604. X        if (kr->QKtype == QK_TEXT) {
  605. X            if ((kr->key) == kcode && (kr->modifiers == modifiers)) {
  606. X                BlockMove(theText, kr->u.QuicText.text, (Size)(theText[0] + 1));
  607. X                return TRUE;
  608. X            }
  609. X        }
  610. X    }
  611. X
  612. X    /* Can't find it in universal, so let's look in program-specific for Hypercard. */
  613. X    kr = qb->quic.application;
  614. X    end = kr + N_QCKEYS;
  615. X
  616. X    for (; kr < end; kr++) {
  617. X        if (kr->QKtype == QK_TEXT) {
  618. X            if ((kr->key) == kcode && (kr->modifiers == modifiers)) {
  619. X                BlockMove(theText, kr->u.QuicText.text, (Size)(theText[0] + 1));
  620. X                return TRUE;
  621. X            }
  622. X        }
  623. X    }
  624. X    return FALSE;
  625. X}
  626. ________This_Is_The_END________
  627. if test `wc -l < SetQuicText.c` -ne 271; then
  628.     echo 'shar: SetQuicText.c was damaged during transit'
  629.   echo '      (should have been 271 bytes)'
  630. fi
  631. fi        ; : end of overwriting check
  632. echo 'Extracting quickeys.h'
  633. if test -f quickeys.h; then echo 'shar: will not overwrite quickeys.h'; else
  634. sed 's/^X//' << '________This_Is_The_END________' > quickeys.h
  635. X/*
  636. X  * QuicKeys.h :    Types and defines for interacting with QuicKeys internals. This information is based
  637. X  *                on Chapter 8 of the QuicKeys manual. Typed in by Dewi Williams. Delphi: DEWI, who is
  638. X  *                responsible for any typos here!
  639. X  *
  640. X  *                The QuicKeys keyboard enhancer is a product of CE Software, 801 73rd Street,
  641. X  *                Des Moines, Iowa 50312. (515) 224-1995.
  642. X  */
  643. X
  644. X
  645. X/* Defines */
  646. X
  647. X/* QuicKey command types (for the QKtype field of the key record). */
  648. X#define    QK_UNUSED    0                    /* Empty key record */
  649. X#define    QK_FILE        1
  650. X#define    QK_TEXT        2
  651. X#define    QK_MENU        3
  652. X#define    QK_DA        4
  653. X#define    QK_OTHER        5
  654. X#define    QK_ALIAS        6
  655. X#define    QK_CLICK        7
  656. X#define    QK_SEQUENCE    8
  657. X#define    QK_BUTTON    9
  658. X
  659. X/* QuicKey "Other" command types. */
  660. X#define    QKO_LINEUP    0
  661. X#define    QKO_LINEDN    1
  662. X#define    QKO_PAGEUP    2
  663. X#define    QKO_PAGEDN    3
  664. X#define    QKO_HOME    4
  665. X#define    QKO_END        5
  666. X#define    QKO_COLLEFT    6
  667. X#define    QKO_COLRIGHT    7
  668. X#define    QKO_PGLEFT    8
  669. X#define    QKO_PGRIGHT    9
  670. X#define    QKO_CLWIND    10
  671. X#define    QKO_ZMWIND    11
  672. X#define    QKO_TRANSFER     12
  673. X#define    QKO_SHUTDN    13
  674. X#define    QKO_RESTART    14
  675. X#define    QKO_SELRWIND    16
  676. X#define    QKO_SEL2WIND    17
  677. X#define    QKO_QUOTES    18
  678. X#define    QKO_DQUOTES    19
  679. X#define    QKO_QUICREF    20
  680. X#define    QKO_TOGGLE    21
  681. X#define    QKO_READ    22
  682. X#define    QKO_DATE1    23
  683. X#define    QKO_DATE2    24
  684. X#define    QKO_DATE3    25
  685. X#define    QKO_DATE4    26
  686. X#define    QKO_DATE5    27
  687. X#define    QKO_DATE6    28
  688. X#define    QKO_DATE7    29
  689. X#define    QKO_DATE8    30
  690. X#define    QKO_TIME1    32
  691. X#define    QKO_TIME2    34
  692. X#define    QKO_FKBASE    101            /* Base for FKEYs. Add ID value on to this. */
  693. X
  694. X#define    N_QCKEYS        100            /* Number of entries in the key record arrays. */
  695. X
  696. X/* Types */
  697. X
  698. X/*
  699. X  * Format of the key record within QuicKeys' system heap block.
  700. X  */
  701. X
  702. Xtypedef struct {
  703. X    unsigned short    key;                /* Keycode and ascii value as returned by GetNextEvent */
  704. X    unsigned short    modifiers;            /* Modifiers as returned by GetNextEvent, masked */
  705. X    short        QKtype;            /* Variant */
  706. X    union {
  707. X        struct {                    /* QuicKeys File */
  708. X            char        filename[32];
  709. X            char        volname[32];
  710. X            long        dirID;
  711. X            ResType    fileType;
  712. X        } QKFile;
  713. X    
  714. X        struct {                    /* QuicKeys text to type */
  715. X            char        text[72];
  716. X        } QuicText;
  717. X
  718. X        struct {                    /* QuicKeys menu */
  719. X            char        menu[72];
  720. X        } QuicMenu;
  721. X
  722. X        struct {                    /* QuicKeys DA */
  723. X            char        da[72];
  724. X        } QuicDA;
  725. X
  726. X        struct {                    /* QuicKeys Other  (e.g. mousies, special, datestamps) */
  727. X            short    cmd;            /* See the defines above starting with "QKO_" */
  728. X        } QuicOther;
  729. X
  730. X        struct {                    /* QuicKeys Alias */
  731. X            unsigned short    key;        /* Replacement keycode and ascii value */
  732. X            unsigned short    modifiers;    /* Replacement modifiers */
  733. X        } QuicAlias;
  734. X
  735. X        struct {                    /* QuicKeys Click */
  736. X            char        title[28];        /* Title of the click */
  737. X            char        wtitle[28];    /* Title of the window to look for */
  738. X            short    nclicks;        /* Number of clicks */
  739. X            short    specific;        /* Look for specific window. Really boolean + pad. */
  740. X            short    mUpFormat;    /* Mouse up format: Absolute/relative/window etc. */
  741. X            Point        mouseUp;
  742. X            short    mDownFormat;    /* Mouse down format: Absolute/relative/window etc. */
  743. X            Point        mouseDown;
  744. X        } QuicClick;
  745. X
  746. X        struct {                    /* QuicKeys Sequence */
  747. X            char        title[12];        /* QuicKeys sequence title */
  748. X            short    step[30];        /* Individual steps of sequence as a keycode/modifiers */
  749. X        } QuicSequence;
  750. X        
  751. X        struct {
  752. X            char        name[72];        /* Name of the button */
  753. X        } QuicButton;
  754. X    } u;
  755. X} KeyRecord;
  756. X
  757. Xtypedef struct {                        /* QuicKeys INIT system heap  block */
  758. X    long            magic;                /* Hex value of a89f1234 */
  759. X    long            signature;                /* CE Software's signature of 'CELN' */
  760. X    long            version;                /* Version number of 0. */
  761. X    ProcPtr        SetLaunch;            /* Vector */
  762. X    long            unknown1;            /* Undocumented */
  763. X    ProcPtr        FindAnApp;            /* Vector */
  764. X    Byte            unknown2[16];            /* Undocumented */
  765. X    ProcPtr        PlotAnItem;            /* Vector */
  766. X    long            unknown3;            /* Undocumented */
  767. X    KeyRecord    universal[N_QCKEYS];    /* Universal keys */
  768. X    KeyRecord    application[N_QCKEYS];    /* Program-specific keys */
  769. X} QuicInit;
  770. X
  771. X/*
  772. X  * And the block together with its memory manager header.
  773. X  */
  774. X
  775. Xtypedef struct {                /* QuicInit and its block header */
  776. X    Byte        header[8];        /* Memory manager block header */
  777. X    QuicInit    quic;
  778. X} QuicInitBlock;
  779. X
  780. X/* Prototypes */
  781. XQuicInitBlock    *FindSysHeap(void);
  782. ________This_Is_The_END________
  783. if test `wc -l < quickeys.h` -ne 147; then
  784.     echo 'shar: quickeys.h was damaged during transit'
  785.   echo '      (should have been 147 bytes)'
  786. fi
  787. fi        ; : end of overwriting check
  788. exit 0
  789.