home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Ph 1.1.1 / PhClient / new.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-08  |  5.5 KB  |  196 lines  |  [TEXT/MPS ]

  1. /*_____________________________________________________________________
  2.  
  3.       new.c - New Ph Record Movable Modal Dialog.
  4. _____________________________________________________________________*/
  5.  
  6. #pragma load "precompile"
  7. #include "rez.h"
  8. #include "new.h"
  9. #include "utl.h"
  10. #include "glob.h"
  11. #include "oop.h"
  12. #include "wstm.h"
  13.  
  14. /*_____________________________________________________________________
  15.  
  16.     Global Variables.
  17. _____________________________________________________________________*/
  18.  
  19. static DialogPtr        Window;            /* ptr to dialog window */
  20. static Str255            Pswd1;            /* first password */
  21. static Str255            Pswd2;            /* second password */
  22.  
  23. static oop_Dispatch dispatch = {
  24.                                 new_DoPeriodic,
  25.                                 oop_DoClick,
  26.                                 new_DoKey,
  27.                                 oop_DoUpdate,
  28.                                 oop_DoActivate,
  29.                                 oop_DoDeactivate,
  30.                                 oop_DoGrow,
  31.                                 oop_DoZoom,
  32.                                 oop_DoClose,
  33.                                 new_DoCommand
  34.                             };
  35.  
  36. /*_____________________________________________________________________
  37.  
  38.     new_DoPeriodic - Do Periodic Tasks.
  39.     
  40.     Entry:    w = pointer to window record.
  41. _____________________________________________________________________*/
  42.  
  43. void new_DoPeriodic (WindowPtr w)
  44.  
  45. {
  46.     short            fNum;                /* edit field number */
  47.  
  48.     oop_DoPeriodic(w);
  49.     fNum = utl_GetDialogEditFieldNum(w);
  50.     if (fNum == newPswdField1 || fNum == newPswdField2)
  51.         glob_CheckPswdSel(w);
  52. }
  53.  
  54. /*_____________________________________________________________________
  55.  
  56.     new_DoKey - Process a Key Down Event.
  57.     
  58.     Entry:    w = pointer to window record.
  59.                 key = ascii code of key.
  60.                 modifiers = modifiers from event record.
  61. _____________________________________________________________________*/
  62.  
  63. void new_DoKey (WindowPtr w, char key, short modifiers)
  64.  
  65. {
  66.     short            fNum;                /* edit field number */
  67.     char            *pswd;            /* pointer to Pswd1 or Pswd2 */
  68.  
  69.     fNum = utl_GetDialogEditFieldNum(w);
  70.     if (fNum == newPswdField1 || fNum == newPswdField2) {
  71.         pswd = fNum == newPswdField1 ? Pswd1 : Pswd2;
  72.         if (!glob_FilterPswdChar(w, key, modifiers, pswd)) return;
  73.     } else {
  74.         if (!glob_FilterAsciiChar(w, key, modifiers)) return;
  75.     }
  76.     oop_DoKey(w, key, modifiers);
  77. }
  78.  
  79. /*_____________________________________________________________________
  80.  
  81.     new_DoCommand - Process a Command.
  82.     
  83.     Entry:    w = pointer to window record.
  84.                 theMenu = menu index.
  85.                 theItem = item index.
  86.                 
  87.     Exit:        function result = true if command handled.
  88. _____________________________________________________________________*/
  89.  
  90. Boolean new_DoCommand (WindowPtr w, short theMenu, short theItem)
  91.  
  92. {
  93.     short            fNum;                /* edit field number */
  94.     char            *pswd;            /* pointer to Pswd1 or Pswd2 */
  95.  
  96.     fNum = utl_GetDialogEditFieldNum(w);
  97.     if (fNum == newPswdField1 || fNum == newPswdField2) {
  98.         pswd = fNum == newPswdField1 ? Pswd1 : Pswd2;
  99.         if (theMenu == editID && theItem != selectAllCmd) {
  100.             glob_FilterPswdEditCmd(w, theItem, pswd);
  101.             return true;
  102.         }
  103.     } else if (theMenu == editID && theItem == pasteCmd &&
  104.         !glob_FilterPaste()) {
  105.         return true;
  106.     }
  107.     return oop_DoCommand(w, theMenu, theItem);
  108. }
  109.  
  110. /*_____________________________________________________________________
  111.  
  112.     InitField - Initialize Dialog Field.
  113.     
  114.     Entry:    fNum = field number.
  115.                 val = field value.
  116.                 hilite = true to hilite (select) this field.
  117. _____________________________________________________________________*/
  118.  
  119. static void InitField (short fNum, Str255 val, Boolean hilite)
  120.  
  121. {
  122.     utl_SetDialogText(Window, fNum, val);
  123.     if (hilite) SelIText(Window, fNum, 0, 0x7fff);
  124. }
  125.  
  126. /*_____________________________________________________________________
  127.  
  128.     new_DoDialog - Do New Ph Record Dialog.
  129.     
  130.     Entry:    alias = initial value for alias field.
  131.                 name = initial value for name field.
  132.                 type = initial value for type field.
  133.                 pswd1 = initial value for first password field.
  134.                 pswd2 = initial value for second password field.
  135.                 whichField = field to hilite initially:
  136.                     0 = alias.
  137.                     1 = name.
  138.                     2 = type.
  139.                     3 = password.
  140.     
  141.     Exit:        function result = true if canceled by user.
  142.                 alias = alias.
  143.                 name = name.
  144.                 type = type.
  145.                 pswd1 = first password.
  146.                 pswd2 = second password.
  147. _____________________________________________________________________*/
  148.  
  149. Boolean new_DoDialog (Str255 alias, Str255 name, Str255 type, Str255 pswd1,
  150.     Str255 pswd2, short whichField)
  151.  
  152. {
  153.     short            itemHit;        /* item hit */
  154.     Str255        bullets;        /* string of bullets for initial password field */
  155.  
  156.     ShowCursor();
  157.     Window = wstm_Restore(true, newDlogID, nil, &NewState);
  158.     InitField(newAliasField, alias, whichField == 0);
  159.     InitField(newNameField, name, whichField == 1);
  160.     InitField(newTypeField, type, whichField == 2);
  161.     utl_CopyPString(Pswd1, pswd1);
  162.     utl_CopyPString(Pswd2, pswd2);
  163.     *bullets = *pswd1;
  164.     memset(bullets+1, '•', *pswd1);
  165.     InitField(newPswdField1, bullets, whichField == 3);
  166.     *bullets = *pswd2;
  167.     memset(bullets+1, '•', *pswd2);
  168.     InitField(newPswdField2, bullets, false);
  169.     SetPort(Window);
  170.     TextFont(0);
  171.     TextSize(12);
  172.     oop_NewDialog(Window, newModal, nil, &dispatch, true, 
  173.         newOK, newCancel);
  174.     ShowWindow(Window);
  175.     while (true) {
  176.         oop_ClearWindItemHit(Window);
  177.         while (!(itemHit = oop_GetWindItemHit(Window)) && !Done) 
  178.             oop_DoEvent(nil, everyEvent, 
  179.                 oop_InForeground() ? shortSleep : longSleep, nil);
  180.         if (Done) itemHit = newCancel;
  181.         if (itemHit == newCancel) break;
  182.         break;
  183.     }
  184.     if (itemHit == newOK) {
  185.         utl_GetDialogText(Window, newAliasField, alias);
  186.         utl_GetDialogText(Window, newNameField, name);
  187.         utl_GetDialogText(Window, newTypeField, type);
  188.         utl_CopyPString(pswd1, Pswd1);
  189.         utl_CopyPString(pswd2, Pswd2);
  190.     }
  191.     wstm_Save(Window, &NewState);
  192.     oop_DoClose(Window);
  193.     InitCursor();
  194.     return itemHit == newCancel;
  195. }
  196.