home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / lpDaemon SRC / lpr Sources / lprDials.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-16  |  7.8 KB  |  330 lines  |  [TEXT/KAHL]

  1. /************************************************************************
  2.  *
  3.  * lprDials.C
  4.  *
  5.  * Modification History :
  6.  *
  7.  ************************************************************************/
  8.  
  9. #include "LPR.H"
  10. #include "lprProtos.H"
  11.  
  12.  
  13. /************************************************************************
  14.  ************************************************************************/
  15. integer doAbout(Boolean init)
  16. {
  17.     DialogRecord    DialStorg;
  18.     DialogPtr        aboutDial;
  19.     WindowPtr        aPort;
  20.     integer            ItemHit;
  21.  
  22.     GetPort(&aPort);
  23.  
  24.     SetPort( aboutDial = GetNewDialog(AboutDLOG,
  25.                                 (Ptr)&DialStorg,
  26.                                         (WindowPtr) -1) );
  27.     ShowWindow(aboutDial);
  28.  
  29.     InstallUserItem(aboutDial, defFrmItm, (ProcPtr)DefaultFrame);
  30.     SetDialText(aboutDial, wSrvrEdit, prt_server);
  31.     SetDialText(aboutDial, wPrtrEdit, prt_name);
  32.     SetDialText(aboutDial, wLoclEdit, my_host);
  33.     SetDialText(aboutDial, wUserEdit, my_user);
  34.     SetDialCtlVal(aboutDial, wSaveChk, (init)?1:0);
  35.  
  36.     ItemHit = 0;
  37.     while ( ItemHit != okBtn )
  38.         {
  39.         ModalDialog(NIL, &ItemHit);
  40.         switch (ItemHit)
  41.             {
  42.             case cancelBtn :
  43.                 Exit();
  44.                 break;
  45.             case wSrvrEdit :
  46.                 break;
  47.             case wPrtrEdit :
  48.                 break;
  49.             case wLoclEdit :
  50.                 break;
  51.             case wUserEdit :
  52.                 break;
  53.             case wSaveChk :
  54.                 ToggleDialCtlVal(aboutDial, wSaveChk);
  55.                 break;
  56.             }
  57.         }
  58.  
  59.     GetDialText(aboutDial, wSrvrEdit, prt_server);
  60.     GetDialText(aboutDial, wPrtrEdit, prt_name);
  61.     GetDialText(aboutDial, wLoclEdit, my_host);
  62.     GetDialText(aboutDial, wUserEdit, my_user);
  63.  
  64.     if ( GetDialCtlVal(aboutDial, wSaveChk) )
  65.         WritePreferences();
  66.  
  67.     SetPort(aPort);
  68.     CloseDialog(aboutDial);
  69.  
  70.     return ItemHit;
  71. }
  72.  
  73. /************************************************************************
  74.  * return FALSE if you want the main event loop to process this event    *
  75.  ************************************************************************/
  76. integer HandleDEvent(EventPtr myEvent)
  77. {
  78.     DialogPtr    whichDial = 0;
  79.     integer        itemHit = 0;
  80.     GrafPtr        aPort;
  81.     stdWinHand    sHand;
  82.  
  83.  
  84.     if (myEvent->what == updateEvt)
  85.         {
  86.         whichDial = (DialogPtr)myEvent->message;
  87.         GetPort(&aPort);
  88.         SetPort(whichDial);
  89.         BeginUpdate(whichDial);
  90.         DrawDialog(whichDial);
  91.         EndUpdate(whichDial);
  92.         SetPort(aPort);
  93.         return FALSE;
  94.         }
  95.  
  96.     DialogSelect(myEvent, &whichDial, &itemHit);
  97.     if (((WindowPeek)whichDial)->windowKind < 0)
  98.         return TRUE;    /* a system window, we should never have got here */
  99.  
  100.     GetPort(&aPort);
  101.     SetPort((GrafPtr)whichDial);
  102.  
  103.     sHand = IsAppWindow(whichDial);
  104.  
  105.     switch (myEvent->what)
  106.         {
  107.         case mouseDown :
  108.             if ( sHand && (*sHand)->clickProc )
  109.                 return FALSE;
  110.             break;
  111.         case keyDown:
  112.         case autoKey:
  113.             if (myEvent->modifiers & cmdKey)
  114.                 return FALSE;
  115.             if ( sHand && (*sHand)->keyProc )
  116.                 return FALSE;
  117.             break;
  118.         case activateEvt :
  119.             if ( sHand && (*sHand)->activateProc )
  120.                 return FALSE;
  121.             break;
  122.         case updateEvt :
  123.             if ( sHand && (*sHand)->updateProc )
  124.                 return FALSE;
  125.             break;
  126.         }
  127.     SetPort(aPort);
  128.  
  129.     return TRUE;
  130. }
  131.  
  132.  
  133. /************************************************************************
  134.  ************************************************************************/
  135. void AlertUser(integer error)
  136. {
  137.     Str255        message;
  138.     GrafPtr        port;
  139.  
  140.     GetPort(&port);
  141.     SetCursor(&arrow);
  142.     GetIndString(message, kErrStrings, error);
  143.     ParamText(message, (StringPtr)"", (StringPtr)"", (StringPtr)"");
  144.     
  145.     Alert(rUserAlert, NIL);
  146.     SetPort(port);
  147. } /* AlertUser */
  148.  
  149.  
  150. /************************************************************************
  151.  ************************************************************************/
  152. integer FileAlert(integer error, integer errNo)
  153. {
  154.     integer        itemHit;
  155.     Str255        message, numb;
  156.     GrafPtr        port;
  157.  
  158.     if (!errNo) return 0;    /* actualy no error */
  159.  
  160.     GetPort(&port);
  161.  
  162.     SetCursor(&arrow);
  163.     /* type Str255 is an array in MPW 3 */
  164.     GetIndString(message, kErrStrings, error);
  165.     NumToString(errNo, numb);
  166.     ParamText(message, numb, (StringPtr)"", (StringPtr)"");
  167.     
  168.     itemHit = Alert(rFileAlert, NIL);
  169.     SetPort(port);
  170.     return errNo;
  171. } /* FileAlert */
  172.  
  173.  
  174.  
  175. /************************************************************************
  176.  ************************************************************************/
  177. DialogPtr         lpr_ban = NIL;
  178. DialogRecord    lpr_rec;
  179.  
  180. pascal void Clock(DialogPtr dial, integer item);
  181. pascal void Scaler(DialogPtr dial, integer item);
  182.  
  183. /************************************************************************
  184.  ************************************************************************/
  185. pascal void Scaler(DialogPtr dial, integer item)
  186. {
  187.     Handle        hand;
  188.     integer        type;
  189.     Rect        rect;
  190.     LongInt        pct = GetWRefCon(dial);
  191.  
  192.     SetPort(dial);
  193.     GetDItem(dial, item, &type, &hand, &rect);
  194.     FrameRect(&rect);
  195.     InsetRect(&rect, 1, 1);
  196.     rect.right = ( ( (rect.right - rect.left) * pct ) / 100 ) + rect.left;
  197.     FillRect(&rect, gray);
  198. }
  199.  
  200. /************************************************************************
  201.  ************************************************************************/
  202. pascal void Clock(DialogPtr dial, integer item)
  203. {
  204.     Handle        hand;
  205.     integer        type;
  206.     Rect        rect;
  207.     LongInt        tick = Ticks % 360;
  208.     LongInt        pat = GetWRefCon(dial);
  209.  
  210.     SetPort(dial);
  211.     GetDItem(dial, item, &type, &hand, &rect);
  212.     PenSize(4, 4);
  213.     FrameOval(&rect);
  214.     InsetRect(&rect, 6, 6);
  215.     EraseArc(&rect, tick,     90);
  216.      FillArc(&rect, tick+ 90, 90, black);
  217.     EraseArc(&rect, tick+180, 90);
  218.      FillArc(&rect, tick+270, 90, black);
  219.  
  220.     PenNormal();
  221. }
  222.  
  223. /************************************************************************
  224.  ************************************************************************/
  225. void LPR_Banner_Up()
  226. {
  227.     if (lpr_ban) return;
  228.  
  229.     lpr_ban = GetNewDialog(129, &lpr_rec, (WindowPtr) -1L);
  230.  
  231.     if (!lpr_ban) return;
  232.  
  233.     SetWRefCon(lpr_ban, 0);
  234.     InstallUserItem(lpr_ban, 2, (ProcPtr)Scaler);
  235.     DrawDialog(lpr_ban);
  236. }
  237.  
  238. /************************************************************************
  239.  ************************************************************************/
  240. void LPR_Banner_Down()
  241. {
  242.     if (lpr_ban)
  243.         CloseDialog(lpr_ban);
  244.     lpr_ban = NIL;
  245. }
  246.  
  247. /************************************************************************
  248.  ************************************************************************/
  249. void LPR_Banner_PCent(LongInt done, LongInt want)
  250. {
  251.     Handle        hand;
  252.     integer        type;
  253.     Rect        rect;
  254.     LongInt        percent;
  255.  
  256.     if (!lpr_ban) return;
  257.  
  258.     if (done == 0)
  259.         {
  260.         SetPort(lpr_ban);
  261.         GetDItem(lpr_ban, 2, &type, &hand, &rect);
  262.         EraseRect(&rect);
  263.         rect.top = 36;
  264.         rect.bottom = rect.top + 24;
  265.         rect.right = rect.left + 332;
  266.         SetDItem(lpr_ban, 2, type, hand, &rect);
  267.         InstallUserItem(lpr_ban, 2, (ProcPtr)Scaler);
  268.         }
  269.  
  270.     if (want > 0) percent = (done * 100)/want;
  271.     else          percent = 100;
  272.     SetWRefCon(lpr_ban, percent);
  273.     Scaler(lpr_ban, 2);
  274. }
  275.  
  276. /************************************************************************
  277.  ************************************************************************/
  278. Boolean NewMessage(integer which, StringPtr message);
  279. Boolean NewMessage(integer which, StringPtr message)
  280. {
  281.     Str255    buffer;
  282.     Byte    *b, *m;
  283.     Byte    c;
  284.     if (!message) return FALSE;
  285.     GetDialText(lpr_ban, which, buffer);
  286.     b = buffer; m = message;
  287.     c = *b + 1;
  288.     while (c--)
  289.         if (*b++ != *m++) return TRUE;
  290.  
  291.     return FALSE;
  292. }
  293.  
  294. /************************************************************************
  295.  ************************************************************************/
  296. void LPR_Banner_Spin(StringPtr message)
  297. {
  298.     Handle        hand;
  299.     integer        type;
  300.     Rect        rect;
  301.  
  302.     if (!lpr_ban) return;
  303.     if (NewMessage(1, message))
  304.         {
  305.         SetPort(lpr_ban);
  306.         SetDialText(lpr_ban, 1, message);
  307.         GetDItem(lpr_ban, 2, &type, &hand, &rect);
  308.         EraseRect(&rect);
  309.         rect.top = 25;
  310.         rect.bottom = rect.top + 70;
  311.         rect.right = rect.left + 70;
  312.         SetDItem(lpr_ban, 2, type, hand, &rect);
  313.         InstallUserItem(lpr_ban, 2, (ProcPtr)Clock);
  314.         }
  315.     Clock(lpr_ban, 2);
  316. }
  317.  
  318. /************************************************************************
  319.  ************************************************************************/
  320. void LPR_Banner_Mess(StringPtr message)
  321. {
  322.     Handle        hand;
  323.     integer        type;
  324.     Rect        rect;
  325.  
  326.     if (!lpr_ban) return;
  327.     if (NewMessage(1, message))
  328.         SetDialText(lpr_ban, 1, message);
  329. }
  330.