home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1997: The Complete Utilities Toolkit / macworld-complete-utilities-1997.iso / Programming / GlueWindow4.2.1 / source(CodeWarrior5) / GW-cdev4.2.1.c next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  22.9 KB  |  882 lines  |  [TEXT/MMCC]

  1. //    GW-cdev4.2.1.c
  2.  
  3. #include    "GW-cdev4.2.1.h"
  4.  
  5. pascal long main(short msg, short item, short numItems, short panelID,
  6.                     EventRecord *eventP, long val, DialogPtr dp)
  7. {
  8.     long    retVal;
  9.         
  10.     retVal = val;
  11.     switch(msg) {
  12.         case nulDev:
  13.         case keyEvtDev:
  14.         case undoDev:
  15.         case cutDev:
  16.         case copyDev:
  17.         case clearDev:
  18.         case activDev:
  19.         case deactivDev:
  20.             break;
  21.         case updateDev:
  22.             setupDialogItems((initDataHandle)val, dp, numItems);
  23.             break;
  24.         case macDev:
  25.             retVal = checkMachine();
  26.             break;
  27.         case initDev:
  28.             retVal = initPanel(dp, numItems);
  29.             break;
  30.         case closeDev:
  31.             closePanel((initDataHandle)val);
  32.             break;
  33.         case hitDev:
  34.             hitItems((initDataHandle)val, dp, item + numItems, eventP, numItems);
  35.             break;
  36.         default:
  37.             break;
  38.     }
  39.     return(retVal);
  40. }
  41.  
  42. //
  43.  
  44. Boolean isSystem7(void)
  45. {
  46.     Boolean    f = false;
  47.     OSErr    err;
  48.     long    res;
  49.     
  50.     if(trapAvailable(_Gestalt)) {
  51.         err = Gestalt(gestaltSystemVersion, &res);
  52.         if(err == noErr && res >= 0x0700)    f = true;
  53.     }
  54.     return(f);
  55. }
  56.  
  57. //    Utils -----
  58.  
  59. Boolean trapAvailable(short theTrap)
  60. {
  61.     TrapType    tType;
  62.     
  63.     tType = getTrapType(theTrap);
  64.     if(tType == ToolTrap)
  65.         theTrap = theTrap & 0x07FF;
  66.     if(theTrap >= numToolboxTrap())
  67.         theTrap = _Unimplemented;
  68.     
  69.     return(NGetTrapAddress(theTrap, tType) !=
  70.             NGetTrapAddress(_Unimplemented, ToolTrap));
  71. }
  72.  
  73. TrapType getTrapType(short theTrap)
  74. {
  75.     if((theTrap & trapMask) > 0)
  76.         return(ToolTrap);
  77.     else
  78.         return(OSTrap);
  79. }
  80.  
  81. short numToolboxTrap(void)
  82. {
  83.     if(NGetTrapAddress(_InitGraf, ToolTrap) ==
  84.             NGetTrapAddress(0xAA6E, ToolTrap))
  85.         return(0x0200);
  86.     else
  87.         return(0x0400);
  88. }
  89.  
  90. //
  91.  
  92. pascal Handle get1Resource(OSType rsrcType, short id)
  93. {
  94.     THz        oldZone;
  95.     Handle    h;
  96.     
  97.     oldZone = GetZone();
  98.     SetZone(SystemZone());
  99.     h = Get1Resource(rsrcType, id);
  100.     SetZone(oldZone);
  101.     return(h);
  102. }
  103.  
  104. //    Load -----
  105.  
  106. initDataHandle load420Data(void)
  107. {
  108.     initDataHandle    dH = nil;
  109.  
  110.     dH = (initDataHandle)get1Resource(myDataType, gw420_DATA_id);
  111.     if(dH) {
  112.         HNoPurge((Handle)dH);
  113.         DetachResource((Handle)dH);
  114.     }
  115.     return(dH);
  116. }
  117.  
  118. OSErr openPrefsFile(prefsFileSpec *pfSpecP)
  119. {
  120.     OSErr    err;
  121.     short    refNum;
  122.     Str255    prefsFileName;
  123.  
  124.     GetIndString(prefsFileName, prefs_STRx_id, nameIndex);
  125.     err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder,
  126.                         &(pfSpecP->vRefNum), &(pfSpecP->DirID));
  127.     if(err == noErr) {
  128.         refNum = HOpenResFile(pfSpecP->vRefNum, pfSpecP->DirID,
  129.                                                     prefsFileName, fsRdWrPerm);    
  130.         if(refNum == -1) {
  131.             return(ResError());
  132.         }
  133.         else {
  134.             pfSpecP->RsrcRefNum = refNum;
  135.             return(noErr);
  136.         }
  137.     }
  138.     return(err);
  139. }
  140.  
  141. void saveSetting(initDataHandle dH)
  142. {
  143.     initDataHandle    tempH;
  144.     Handle            h;
  145.     
  146.     tempH = (initDataHandle)NewHandle(sizeof(initData));
  147.     if(tempH) {
  148.         **tempH = **dH;
  149.         h = Get1Resource(myDataType, gw420_DATA_id);
  150.         if(h)
  151.             RemoveResource(h);
  152.         AddResource((Handle)tempH, myDataType, gw420_DATA_id, "\p");
  153.         ReleaseResource((Handle)tempH);
  154.     }
  155. }
  156.  
  157. //    Event routines    -----
  158.  
  159. long checkMachine(void)
  160. {
  161.     long    retVal = 0;
  162.     
  163.     if(trapAvailable(_Gestalt)) {
  164.         if(isSystem7()) {
  165.             retVal = 1;
  166.         }
  167.     }
  168.     if(retVal == 0) {
  169.         StopAlert(system7_ALRT_id, nil);
  170.     }
  171.     return(retVal);
  172. }
  173.  
  174. long initPanel(DialogPtr dp, short numItems)
  175. {
  176.     initDataHandle    ih = nil, workH = nil;
  177.     OSErr            err;
  178.     short            savedRefNum;
  179.     prefsFileSpec    pf;
  180.     Str255            str;
  181.     
  182.     SetPort(dp);
  183.     ih = getSetting();
  184.     if(ih) {
  185.         savedRefNum = CurResFile();
  186.         err = openPrefsFile(&pf);
  187.         if(err == noErr) {
  188.             workH = load420Data();
  189.             CloseResFile(pf.RsrcRefNum);
  190.         }
  191.         else {
  192.             NumToString(err, str);
  193.             ParamText(str, "\p", "\p", "\p");
  194.             CautionAlert(error_ALRT_id, nil);
  195.         }
  196.         UseResFile(savedRefNum);
  197.         
  198.         if(workH) {
  199.             setupDialogItems(ih, dp, numItems);
  200.             DisposeHandle((Handle)workH);
  201.         }
  202.         else {
  203.             StopAlert(prefs_ALRT_id, nil);
  204.             return(cdevGenErr);
  205.         }
  206.     }
  207.     else {
  208.         StopAlert(restart_ALRT_id, nil);
  209.         return(cdevGenErr);
  210.     }
  211.     return((long)ih);
  212. }
  213.  
  214. initDataHandle getSetting(void)
  215. {
  216.     initDataHandle    ih = nil;
  217.     long            ihAddress;
  218.     OSErr            err;
  219.     
  220.     err = Gestalt(myCreator, &ihAddress);
  221.     if(err == noErr) {
  222.         ih = (initDataHandle)ihAddress;
  223.     }
  224.     return(ih);
  225. }
  226.  
  227. void hitItems(initDataHandle ih, DialogPtr dp, short item,
  228.                 EventRecord *eventP, short numItems)
  229. {
  230.     short    itemType;
  231.     Handle    h;
  232.     Rect    r;
  233.  
  234.     switch(item) {
  235.         case checkDragOn:
  236.             (**ih).dragOn = !(**ih).dragOn;
  237.             setCheckButton(dp, checkDragOn        + numItems, (**ih).dragOn);
  238.             if((**ih).noMarquee && (**ih).dragOn)
  239.                 setActive(ih, dp, numItems, checkDragCtrl);
  240.             else
  241.                 setInactive(ih, dp, numItems, checkDragCtrl);
  242.             break;
  243.         case checkNoMarquee:
  244.             (**ih).noMarquee = !(**ih).noMarquee;
  245.             setCheckButton(dp, checkNoMarquee    + numItems, (**ih).noMarquee);
  246.             if((**ih).noMarquee && (**ih).dragOn)
  247.                 setActive(ih, dp, numItems, checkDragCtrl);
  248.             else
  249.                 setInactive(ih, dp, numItems, checkDragCtrl);
  250.             break;
  251.         case checkGlueOn:
  252.             (**ih).glueOn = !(**ih).glueOn;
  253.             setCheckButton(dp, checkGlueOn        + numItems, (**ih).glueOn);
  254.             if((**ih).glueOn)
  255.                 setActive(ih, dp, numItems, checkGlueCtrl);
  256.             else
  257.                 setInactive(ih, dp, numItems, checkGlueCtrl);
  258.             break;
  259.         case checkGrowOn:
  260.             (**ih).growOn = !(**ih).growOn;
  261.             setCheckButton(dp, checkGrowOn        + numItems, (**ih).growOn);
  262.             break;
  263.         case checkPushOn:
  264.             (**ih).pushOn = !(**ih).pushOn;
  265.             setCheckButton(dp, checkPushOn        + numItems, (**ih).pushOn);
  266.             if((**ih).pushOn) {
  267.                 GetDialogItem(dp, numItems + checkPushSound, &itemType, &h, &r);
  268.                 HiliteControl((ControlHandle)h, itemActive);
  269.                 setActive(ih, dp, numItems, checkPushCtrl);
  270.             }
  271.             else {
  272.                 GetDialogItem(dp, numItems + checkPushSound, &itemType, &h, &r);
  273.                 HiliteControl((ControlHandle)h, itemInactive);
  274.                 setInactive(ih, dp, numItems, checkPushCtrl);
  275.             }
  276.             break;
  277.         case checkPopOn:
  278.             (**ih).popOn = !(**ih).popOn;
  279.             setCheckButton(dp, checkPopOn        + numItems, (**ih).popOn);
  280.             if((**ih).popOn) {
  281.                 GetDialogItem(dp, numItems + checkPopSound, &itemType, &h, &r);
  282.                 HiliteControl((ControlHandle)h, itemActive);
  283.                 setActive(ih, dp, numItems, checkPopCtrl);
  284.             }
  285.             else {
  286.                 GetDialogItem(dp, numItems + checkPopSound, &itemType, &h, &r);
  287.                 HiliteControl((ControlHandle)h, itemInactive);
  288.                 setInactive(ih, dp, numItems, checkPopCtrl);
  289.             }
  290.             break;
  291.         case checkPushSound:
  292.             (**ih).pushSound = !(**ih).pushSound;
  293.             setCheckButton(dp, checkPushSound    + numItems, (**ih).pushSound);
  294.             break;
  295.         case checkPopSound:
  296.             (**ih).popSound = !(**ih).popSound;
  297.             setCheckButton(dp, checkPopSound    + numItems, (**ih).popSound);
  298.             break;
  299.         case checkShowIcon:
  300.             (**ih).showIcon = !(**ih).showIcon;
  301.             setCheckButton(dp, checkShowIcon    + numItems, (**ih).showIcon);
  302.             break;
  303.         case checkDragCtrl:
  304.         case checkDragShift:
  305.         case checkDragOption:
  306.         case checkDragCommand:
  307.             if((**ih).noMarquee) {
  308.                 (**ih).dragKey[item - checkDragCtrl]
  309.                     = !(**ih).dragKey[item - checkDragCtrl];
  310.             }
  311.             setCheckButton(dp, checkDragCtrl    + numItems, (**ih).dragKey[0]);
  312.             setCheckButton(dp, checkDragShift    + numItems, (**ih).dragKey[1]);
  313.             setCheckButton(dp, checkDragOption    + numItems, (**ih).dragKey[2]);
  314.             setCheckButton(dp, checkDragCommand    + numItems, (**ih).dragKey[3]);
  315.             break;
  316.         case checkGlueCtrl:
  317.         case checkGlueShift:
  318.         case checkGlueOption:
  319.         case checkGlueCommand:
  320.             if((**ih).glueOn) {
  321.                 (**ih).glueKey[item - checkGlueCtrl]
  322.                     = !(**ih).glueKey[item - checkGlueCtrl];
  323.             }
  324.             setCheckButton(dp, checkGlueCtrl    + numItems, (**ih).glueKey[0]);
  325.             setCheckButton(dp, checkGlueShift    + numItems, (**ih).glueKey[1]);
  326.             setCheckButton(dp, checkGlueOption    + numItems, (**ih).glueKey[2]);
  327.             setCheckButton(dp, checkGlueCommand    + numItems, (**ih).glueKey[3]);
  328.             break;
  329.         case checkPushCtrl:
  330.         case checkPushShift:
  331.         case checkPushOption:
  332.         case checkPushCommand:
  333.             if((**ih).pushOn) {
  334.                 (**ih).pushKey[item - checkPushCtrl]
  335.                     = !(**ih).pushKey[item - checkPushCtrl];
  336.                 checkKeyCombination(ih, item - checkPushCtrl);
  337.             }
  338.             setCheckButton(dp, checkPushCtrl    + numItems, (**ih).pushKey[0]);
  339.             setCheckButton(dp, checkPushShift    + numItems, (**ih).pushKey[1]);
  340.             setCheckButton(dp, checkPushOption    + numItems, (**ih).pushKey[2]);
  341.             setCheckButton(dp, checkPushCommand    + numItems, (**ih).pushKey[3]);
  342.             break;
  343.         case checkPopCtrl:
  344.         case checkPopShift:
  345.         case checkPopOption:
  346.         case checkPopCommand:
  347.             if((**ih).popOn) {
  348.                 (**ih).popKey[item - checkPopCtrl]
  349.                     = !(**ih).popKey[item - checkPopCtrl];
  350.                 checkKeyCombination(ih, item - checkPopCtrl);
  351.             }
  352.             setCheckButton(dp, checkPopCtrl        + numItems, (**ih).popKey[0]);
  353.             setCheckButton(dp, checkPopShift    + numItems, (**ih).popKey[1]);
  354.             setCheckButton(dp, checkPopOption    + numItems, (**ih).popKey[2]);
  355.             setCheckButton(dp, checkPopCommand    + numItems, (**ih).popKey[3]);
  356.             break;
  357.         case buttonDragCtrl:
  358.         case buttonDragShift:
  359.         case buttonDragOption:
  360.         case buttonDragCommand:
  361.             if((**ih).noMarquee) {
  362.                 if(trackButton(dp, numItems, item, item - buttonDragCtrl)) {
  363.                     (**ih).dragKey[item - buttonDragCtrl]
  364.                         = !(**ih).dragKey[item - buttonDragCtrl];
  365.                 }
  366.             }
  367.             setCheckButton(dp, checkDragCtrl    + numItems, (**ih).dragKey[0]);
  368.             setCheckButton(dp, checkDragShift    + numItems, (**ih).dragKey[1]);
  369.             setCheckButton(dp, checkDragOption    + numItems, (**ih).dragKey[2]);
  370.             setCheckButton(dp, checkDragCommand    + numItems, (**ih).dragKey[3]);
  371.             break;
  372.         case buttonGlueCtrl:
  373.         case buttonGlueShift:
  374.         case buttonGlueOption:
  375.         case buttonGlueCommand:
  376.             if((**ih).glueOn) {
  377.                 if(trackButton(dp, numItems, item, item - buttonGlueCtrl)) {
  378.                     (**ih).glueKey[item - buttonGlueCtrl]
  379.                         = !(**ih).glueKey[item - buttonGlueCtrl];
  380.                 }
  381.             }
  382.             setCheckButton(dp, checkGlueCtrl    + numItems, (**ih).glueKey[0]);
  383.             setCheckButton(dp, checkGlueShift    + numItems, (**ih).glueKey[1]);
  384.             setCheckButton(dp, checkGlueOption    + numItems, (**ih).glueKey[2]);
  385.             setCheckButton(dp, checkGlueCommand    + numItems, (**ih).glueKey[3]);
  386.             break;
  387.         case buttonPushCtrl:
  388.         case buttonPushShift:
  389.         case buttonPushOption:
  390.         case buttonPushCommand:
  391.             if((**ih).pushOn) {
  392.                 if(trackButton(dp, numItems, item, item - buttonPushCtrl)) {
  393.                     (**ih).pushKey[item - buttonPushCtrl]
  394.                         = !(**ih).pushKey[item - buttonPushCtrl];
  395.                     checkKeyCombination(ih, item - buttonPushCtrl);
  396.                 }
  397.             }
  398.             setCheckButton(dp, checkPushCtrl    + numItems, (**ih).pushKey[0]);
  399.             setCheckButton(dp, checkPushShift    + numItems, (**ih).pushKey[1]);
  400.             setCheckButton(dp, checkPushOption    + numItems, (**ih).pushKey[2]);
  401.             setCheckButton(dp, checkPushCommand    + numItems, (**ih).pushKey[3]);
  402.             break;
  403.         case buttonPopCtrl:
  404.         case buttonPopShift:
  405.         case buttonPopOption:
  406.         case buttonPopCommand:
  407.             if((**ih).popOn) {
  408.                 if(trackButton(dp, numItems, item, item - buttonPopCtrl)) {
  409.                     (**ih).popKey[item - buttonPopCtrl]
  410.                         = !(**ih).popKey[item - buttonPopCtrl];
  411.                     checkKeyCombination(ih, item - buttonPopCtrl);
  412.                 }
  413.             }
  414.             setCheckButton(dp, checkPopCtrl        + numItems, (**ih).popKey[0]);
  415.             setCheckButton(dp, checkPopShift    + numItems, (**ih).popKey[1]);
  416.             setCheckButton(dp, checkPopOption    + numItems, (**ih).popKey[2]);
  417.             setCheckButton(dp, checkPopCommand    + numItems, (**ih).popKey[3]);
  418.             break;
  419.         case buttonAbout:
  420.             if(trackAbout(dp, numItems))
  421.                 about(dp);
  422.             break;
  423.         default:
  424.             break;
  425.     }
  426. }
  427.  
  428. void setupDialogItems(initDataHandle ih, DialogPtr dp, short numItems)
  429. {
  430.     setCheckButton(dp, checkDragOn        + numItems, (**ih).dragOn);
  431.     setCheckButton(dp, checkNoMarquee    + numItems, (**ih).noMarquee);
  432.     setCheckButton(dp, checkGlueOn        + numItems, (**ih).glueOn);
  433.     setCheckButton(dp, checkGrowOn        + numItems, (**ih).growOn);
  434.     setCheckButton(dp, checkPushOn        + numItems, (**ih).pushOn);
  435.     setCheckButton(dp, checkPopOn        + numItems, (**ih).popOn);
  436.     setCheckButton(dp, checkPushSound    + numItems, (**ih).pushSound);
  437.     setCheckButton(dp, checkPopSound    + numItems, (**ih).popSound);
  438.     setCheckButton(dp, checkShowIcon    + numItems, (**ih).showIcon);
  439.     setCheckButton(dp, checkDragCtrl    + numItems, (**ih).dragKey[0]);
  440.     setCheckButton(dp, checkDragShift    + numItems, (**ih).dragKey[1]);
  441.     setCheckButton(dp, checkDragOption    + numItems, (**ih).dragKey[2]);
  442.     setCheckButton(dp, checkDragCommand    + numItems, (**ih).dragKey[3]);
  443.     setCheckButton(dp, checkGlueCtrl    + numItems, (**ih).glueKey[0]);
  444.     setCheckButton(dp, checkGlueShift    + numItems, (**ih).glueKey[1]);
  445.     setCheckButton(dp, checkGlueOption    + numItems, (**ih).glueKey[2]);
  446.     setCheckButton(dp, checkGlueCommand    + numItems, (**ih).glueKey[3]);
  447.     setCheckButton(dp, checkPushCtrl    + numItems, (**ih).pushKey[0]);
  448.     setCheckButton(dp, checkPushShift    + numItems, (**ih).pushKey[1]);
  449.     setCheckButton(dp, checkPushOption    + numItems, (**ih).pushKey[2]);
  450.     setCheckButton(dp, checkPushCommand    + numItems, (**ih).pushKey[3]);
  451.     setCheckButton(dp, checkPopCtrl        + numItems, (**ih).popKey[0]);
  452.     setCheckButton(dp, checkPopShift    + numItems, (**ih).popKey[1]);
  453.     setCheckButton(dp, checkPopOption    + numItems, (**ih).popKey[2]);
  454.     setCheckButton(dp, checkPopCommand    + numItems, (**ih).popKey[3]);
  455.     
  456.     setHilite(ih, dp, numItems);
  457. }
  458.  
  459. void setHilite(initDataHandle ih, DialogPtr dp, short numItems)
  460. {
  461.     short         itemType;
  462.     Handle        h, iconH;
  463.     Rect        r;
  464.     Boolean        colorIcon;
  465.     
  466.     colorIcon = trapAvailable(_GetCIcon);
  467.     GetDialogItem(dp, numItems + buttonAbout, &itemType, &h, &r);
  468.     if(colorIcon) {
  469.         iconH = (Handle)GetCIcon(aboutup_cicn_id);
  470.         PlotCIcon(&r, (CIconHandle)iconH);
  471.         DisposeCIcon((CIconHandle)iconH);
  472.     }
  473.     else {
  474.         iconH = GetIcon(aboutup_cicn_id);
  475.         PlotIcon(&r, iconH);
  476.         DisposeHandle(iconH);
  477.     }
  478.     
  479.     if((**ih).noMarquee && (**ih).dragOn)
  480.         setActive(ih, dp, numItems, checkDragCtrl);
  481.     else
  482.         setInactive(ih, dp, numItems, checkDragCtrl);
  483.     
  484.     if((**ih).glueOn)
  485.         setActive(ih, dp, numItems, checkGlueCtrl);
  486.     else
  487.         setInactive(ih, dp, numItems, checkGlueCtrl);
  488.     
  489.     
  490.     if((**ih).pushOn) {
  491.         GetDialogItem(dp, numItems + checkPushSound, &itemType, &h, &r);
  492.         HiliteControl((ControlHandle)h, itemActive);
  493.         setActive(ih, dp, numItems, checkPushCtrl);
  494.     }
  495.     else {
  496.         GetDialogItem(dp, numItems + checkPushSound, &itemType, &h, &r);
  497.         HiliteControl((ControlHandle)h, itemInactive);
  498.         setInactive(ih, dp, numItems, checkPushCtrl);
  499.     }
  500.     
  501.     if((**ih).popOn) {
  502.         GetDialogItem(dp, numItems + checkPopSound, &itemType, &h, &r);
  503.         HiliteControl((ControlHandle)h, itemActive);
  504.         setActive(ih, dp, numItems, checkPopCtrl);
  505.     }
  506.     else {
  507.         GetDialogItem(dp, numItems + checkPopSound, &itemType, &h, &r);
  508.         HiliteControl((ControlHandle)h, itemInactive);
  509.         setInactive(ih, dp, numItems, checkPopCtrl);
  510.     }
  511. }
  512.  
  513. void setActive(initDataHandle ih, DialogPtr dp, short numItems, short item)
  514. {
  515.     short         itemType, i;
  516.     Handle        h, activeIconH, textIconH;
  517.     Rect        r;
  518.     Boolean        colorIcon;
  519.     
  520.     colorIcon = trapAvailable(_GetCIcon);
  521.     if(colorIcon)
  522.         activeIconH = (Handle)GetCIcon(active_cicn_id);
  523.     else
  524.         activeIconH = GetIcon(active_cicn_id);
  525.         
  526.     for(i = 0; i <= 3; i++) {
  527.         GetDialogItem(dp, numItems + item + i, &itemType, &h, &r);
  528.         HiliteControl((ControlHandle)h, itemActive);
  529.         GetDialogItem(dp, numItems + item + 4 + i, &itemType, &h, &r);
  530.         if(colorIcon) {
  531.             PlotCIcon(&r, (CIconHandle)activeIconH);
  532.             textIconH = (Handle)GetCIcon(ctrl_cicn_id + i);
  533.         }
  534.         else {
  535.             PlotIcon(&r, activeIconH);
  536.             textIconH = GetIcon(ctrl_cicn_id + i);
  537.         }
  538.         r.left    += 6;
  539.         r.top    += 5;
  540.         r.right    -= 10;
  541.         r.bottom-= 3;
  542.         if(colorIcon) {
  543.             PlotCIcon(&r, (CIconHandle)textIconH);
  544.             DisposeCIcon((CIconHandle)textIconH);
  545.         }
  546.         else {
  547.             PlotIcon(&r, textIconH);
  548.             DisposeHandle(textIconH);
  549.         }
  550.     }
  551.     if(colorIcon)
  552.         DisposeCIcon((CIconHandle)activeIconH);
  553.     else
  554.         DisposeHandle(activeIconH);
  555. }
  556.  
  557. void setInactive(initDataHandle ih, DialogPtr dp, short numItems, short item)
  558. {
  559.     short         itemType, i;
  560.     Handle        h, iconH;
  561.     Rect        r;
  562.     Boolean        colorIcon;
  563.     
  564.     colorIcon = trapAvailable(_GetCIcon);
  565.     if(colorIcon)
  566.         iconH = (Handle)GetCIcon(inactive_cicn_id);
  567.     else
  568.         iconH = GetIcon(inactive_cicn_id);
  569.     
  570.     for(i = 0; i <= 3; i++) {
  571.         GetDialogItem(dp, numItems + item + i, &itemType, &h, &r);
  572.         HiliteControl((ControlHandle)h, itemInactive);
  573.         GetDialogItem(dp, numItems + item + 4 + i, &itemType, &h, &r);
  574.         if(colorIcon)
  575.             PlotCIcon(&r,(CIconHandle)iconH);
  576.         else
  577.             PlotIcon(&r, iconH);
  578.     }
  579.     if(colorIcon)
  580.         DisposeCIcon((CIconHandle)iconH);
  581.     else
  582.         DisposeHandle(iconH);
  583. }
  584.  
  585. void setCheckButton(DialogPtr dp, short item, Boolean isOn)
  586. {
  587.     short    itemType;
  588.     Handle    h;
  589.     Rect    r;
  590.     
  591.     GetDialogItem(dp, item, &itemType, &h, &r);
  592.     if(isOn)    SetControlValue((ControlHandle)h, 1);
  593.     else        SetControlValue((ControlHandle)h, 0);
  594. }
  595.  
  596. void checkKeyCombination(initDataHandle ih, short key)
  597. {
  598.     if(    ((**ih).pushKey[0] == false) &&
  599.         ((**ih).pushKey[1] == false) &&
  600.         ((**ih).pushKey[2] == false) &&
  601.         ((**ih).pushKey[3] == false) )        (**ih).pushKey[key] = true;
  602.     if(    ((**ih).popKey[0] == false) &&
  603.         ((**ih).popKey[1] == false) &&
  604.         ((**ih).popKey[2] == false) &&
  605.         ((**ih).popKey[3] == false) )        (**ih).popKey[key] = true;
  606. }
  607.  
  608. Boolean trackButton(DialogPtr dp, short numItems, short item, short key)
  609. {
  610.     short    itemType;
  611.     Handle    h, downIconH, upIconH, textIconH;
  612.     Rect    buttonRect, textRect;
  613.     Point    pt;
  614.     Boolean    keyDown, colorIcon;
  615.     
  616.     colorIcon = trapAvailable(_GetCIcon);
  617.     GetDialogItem(dp, numItems + item, &itemType, &h, &buttonRect);
  618.     textRect = buttonRect;
  619.     textRect.left    += 6;
  620.     textRect.top    += 4;
  621.     textRect.right    -= 10;
  622.     textRect.bottom-= 4;
  623.     if(colorIcon) {
  624.         upIconH = (Handle)GetCIcon(active_cicn_id);
  625.         downIconH = (Handle)GetCIcon(down_cicn_id);
  626.         textIconH = (Handle)GetCIcon(key + ctrl_cicn_id);
  627.         PlotCIcon(&buttonRect, (CIconHandle)downIconH);
  628.         PlotCIcon(&textRect, (CIconHandle)textIconH);
  629.     }
  630.     else {
  631.         upIconH = GetIcon(active_cicn_id);
  632.         downIconH = GetIcon(down_cicn_id);
  633.         textIconH = GetIcon(key + ctrl_cicn_id);
  634.         PlotIcon(&buttonRect, downIconH);
  635.         PlotIcon(&textRect, textIconH);
  636.     }
  637.     keyDown = true;
  638.     while(StillDown()) {
  639.         GetMouse(&pt);
  640.         if(!PtInRect(pt, &buttonRect)) {
  641.             if(keyDown) {
  642.                 OffsetRect(&textRect, 0, 1);
  643.                 if(colorIcon) {
  644.                     PlotCIcon(&buttonRect, (CIconHandle)upIconH);
  645.                     PlotCIcon(&textRect, (CIconHandle)textIconH);
  646.                 }
  647.                 else {
  648.                     PlotIcon(&buttonRect, upIconH);
  649.                     PlotIcon(&textRect, textIconH);
  650.                 }
  651.                 keyDown = false;                
  652.             }
  653.         }
  654.         else if(!keyDown) {
  655.             OffsetRect(&textRect, 0, -1);
  656.             if(colorIcon) {
  657.                 PlotCIcon(&buttonRect, (CIconHandle)downIconH);
  658.                 PlotCIcon(&textRect, (CIconHandle)textIconH);
  659.             }
  660.             else {
  661.                 PlotIcon(&buttonRect, downIconH);
  662.                 PlotIcon(&textRect, textIconH);
  663.             }
  664.             keyDown = true;
  665.         }
  666.     }
  667.     if(keyDown) {
  668.         OffsetRect(&textRect, 0, 1);
  669.         if(colorIcon) {
  670.             PlotCIcon(&buttonRect, (CIconHandle)upIconH);
  671.             PlotCIcon(&textRect, (CIconHandle)textIconH);
  672.         }
  673.         else {
  674.             PlotIcon(&buttonRect, upIconH);
  675.             PlotIcon(&textRect, textIconH);
  676.         }
  677.     }
  678.     if(colorIcon) {
  679.         DisposeCIcon((CIconHandle)downIconH);
  680.         DisposeCIcon((CIconHandle)upIconH);
  681.         DisposeCIcon((CIconHandle)textIconH);
  682.     }
  683.     else {
  684.         DisposeHandle(downIconH);
  685.         DisposeHandle(upIconH);
  686.         DisposeHandle(textIconH);
  687.     }
  688.     return(keyDown);
  689. }
  690.  
  691. void closePanel(initDataHandle ih)
  692. {
  693.     short            savedRefNum, i;
  694.     prefsFileSpec    pf;
  695.     Str255            str[4];
  696.     
  697.     for(i = 0; i <= 3; i++) {
  698.         GetIndString(str[i], keys_STRx_id, i + 1);
  699.     }
  700.     if(    (**ih).pushOn && (**ih).noMarquee &&
  701.                     checkSameKeys((**ih).pushKey, (**ih).dragKey) ) {
  702.         ParamText(str[0], str[2], "\p", "\p");
  703.         NoteAlert(samekeys_ALRT_id, nil);
  704.         (**ih).pushOn = false;
  705.     }
  706.     if(    (**ih).dragOn && (**ih).popOn &&
  707.                     checkSameKeys((**ih).dragKey, (**ih).popKey) ) {
  708.         ParamText(str[0], str[3], "\p", "\p");
  709.         NoteAlert(samekeys_ALRT_id, nil);
  710.         (**ih).popOn = false;
  711.     }
  712.     if(    (**ih).pushOn && (**ih).popOn &&
  713.                     checkSameKeys((**ih).pushKey, (**ih).popKey) ) {
  714.         ParamText(str[2], str[3], "\p", "\p");
  715.         NoteAlert(samekeys_ALRT_id, nil);
  716.         (**ih).popOn = false;
  717.     }
  718.     if(    (**ih).pushOn && (**ih).glueOn &&
  719.                     checkSameKeys((**ih).pushKey, (**ih).glueKey) ) {
  720.         ParamText(str[1], str[2], "\p", "\p");
  721.         NoteAlert(samekeys_ALRT_id, nil);
  722.         (**ih).pushOn = false;
  723.     }
  724.     if(    (**ih).glueOn && (**ih).popOn &&
  725.                     checkSameKeys((**ih).glueKey, (**ih).popKey) ) {
  726.         ParamText(str[1], str[3], "\p", "\p");
  727.         NoteAlert(samekeys_ALRT_id, nil);
  728.         (**ih).popOn = false;
  729.     }
  730.     if(    (**ih).glueOn && (**ih).dragOn &&
  731.                     checkSameKeys((**ih).glueKey, (**ih).dragKey) ) {
  732.         ParamText(str[0], str[1], "\p", "\p");
  733.         NoteAlert(samekeys_ALRT_id, nil);
  734.         (**ih).glueOn = false;
  735.     }
  736.     savedRefNum = CurResFile();    
  737.     openPrefsFile(&pf);
  738.     saveSetting(ih);
  739.     CloseResFile(pf.RsrcRefNum);
  740.     UseResFile(savedRefNum);
  741. }
  742.  
  743. Boolean checkSameKeys(Boolean *key1, Boolean *key2)
  744. {
  745.     if(    (*(key1 + 0) == *(key2 + 0)) &&
  746.         (*(key1 + 1) == *(key2 + 1)) &&
  747.         (*(key1 + 2) == *(key2 + 2)) &&
  748.         (*(key1 + 3) == *(key2 + 3)) )         return(true);
  749.         
  750.     return(false);
  751. }
  752.         
  753. Boolean trackAbout(DialogPtr dp, short numItems)
  754. {
  755.     short    itemType;
  756.     Handle    h, downIconH, upIconH;
  757.     Rect    buttonRect;
  758.     Point    pt;
  759.     Boolean    keyDown, colorIcon;
  760.     
  761.     colorIcon = trapAvailable(_GetCIcon);
  762.     GetDialogItem(dp, numItems + buttonAbout, &itemType, &h, &buttonRect);
  763.     if(colorIcon) {
  764.         upIconH = (Handle)GetCIcon(aboutup_cicn_id);
  765.         downIconH = (Handle)GetCIcon(aboutdown_cicn_id);
  766.         PlotCIcon(&buttonRect, (CIconHandle)downIconH);
  767.     }
  768.     else {
  769.         upIconH = GetIcon(aboutup_cicn_id);
  770.         downIconH = GetIcon(aboutdown_cicn_id);
  771.         PlotIcon(&buttonRect, downIconH);
  772.     }
  773.     keyDown = true;
  774.     while(StillDown()) {
  775.         GetMouse(&pt);
  776.         if(!PtInRect(pt, &buttonRect)) {
  777.             if(keyDown) {
  778.                 if(colorIcon)
  779.                     PlotCIcon(&buttonRect, (CIconHandle)upIconH);
  780.                 else
  781.                     PlotIcon(&buttonRect, upIconH);
  782.                 keyDown = false;                
  783.             }
  784.         }
  785.         else if(!keyDown) {
  786.             if(colorIcon)
  787.                 PlotCIcon(&buttonRect, (CIconHandle)downIconH);
  788.             else
  789.                 PlotIcon(&buttonRect, downIconH);
  790.             keyDown = true;
  791.         }
  792.     }
  793.     if(keyDown) {
  794.         if(colorIcon)
  795.             PlotCIcon(&buttonRect, (CIconHandle)upIconH);
  796.         else
  797.             PlotIcon(&buttonRect, upIconH);
  798.     }
  799.     if(colorIcon) {
  800.         DisposeCIcon((CIconHandle)downIconH);
  801.         DisposeCIcon((CIconHandle)upIconH);
  802.     }
  803.     else {
  804.         DisposeHandle(downIconH);
  805.         DisposeHandle(upIconH);
  806.     }
  807.     
  808.     return(keyDown);
  809. }
  810.  
  811. void about(DialogPtr dp)
  812. {
  813.     GrafPtr            savedPortP;
  814.     PenState        savedPenState;
  815.     WindowPtr        wp;
  816.     EventRecord        anEvent;
  817.     PicHandle        titleH;
  818.     Handle            iconH;
  819.     Rect            r;
  820.     Str255            str;
  821.     short            i;
  822.     long            numOfStr;
  823.     Boolean            exitDraw = false, colorIcon;
  824.     Pattern            gray = {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
  825.  
  826.     GetPort(&savedPortP);
  827.     GetPenState(&savedPenState);
  828.  
  829.     SetRect(&r, 5, 5, 5 + 143, 5 + 30);    //    143, 30 are width and height of title.
  830.     wp = GetNewWindow(about_WIND_id, 0, (WindowPtr)-1);
  831.     ShowWindow(wp);
  832.     SetPort(wp);
  833.     titleH = GetPicture(title_PICT_id);
  834.     DrawPicture(titleH, &r);
  835.     PenNormal();
  836.     TextSize(9);
  837.     GetIndString(str, numof_STRx_id, 1);
  838.     StringToNum(str, &numOfStr);
  839.     for(i = 0; i <= numOfStr; i++) {
  840.         GetIndString(str, about_STRx_id, i + 1);
  841.         MoveTo(20, 45 + i * 12);
  842.         DrawString(str); 
  843.     }
  844.     SetRect(&r, 280, 0, 280 + 48, 0 + 48);    //    48, 48 are width and height of window icon.
  845.     colorIcon = trapAvailable(_GetCIcon);
  846.     if(colorIcon) {
  847.         iconH = (Handle)GetCIcon(window_cicn_id);
  848.         PlotCIcon(&r, (CIconHandle)iconH);
  849.     }
  850.     else {
  851.         iconH = GetIcon(window_cicn_id);
  852.         PlotIcon(&r, iconH);
  853.     }
  854.     SetRect(&r, 1, 0, 49, 48);
  855.     PenPat(&gray);
  856.     PenMode(patXor);
  857.     FrameRect(&r);
  858.     while(!exitDraw) {
  859.         FrameRect(&r);
  860.         OffsetRect(&r, 2, 0);
  861.         FrameRect(&r);
  862.         if(r.left == (280 - 47)) {
  863.             exitDraw = true;
  864.             if(colorIcon)
  865.                 PlotCIcon(&r, (CIconHandle)iconH);
  866.             else
  867.                 PlotIcon(&r, iconH);
  868.         }
  869.     }
  870.     while(!(WaitNextEvent(mDownMask, &anEvent, 100, 0))) {
  871.     }
  872.     
  873.     if(colorIcon)
  874.         DisposeCIcon((CIconHandle)iconH);
  875.     else
  876.         DisposeHandle(iconH);
  877.     DisposeWindow(wp);
  878.     SetPort(savedPortP);
  879.     SetPenState(&savedPenState);
  880.     FlushEvents(everyEvent, 0);
  881. }
  882.