home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / time / dclock16.lha / DClock16 / src / SetAlarm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-05  |  6.3 KB  |  241 lines

  1. /*
  2.  *  Source generated with GadToolsBox V1.4
  3.  *  which is (c) Copyright 1991,92 Jaba Development
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <intuition/intuition.h>
  8. #include <intuition/classes.h>
  9. #include <intuition/classusr.h>
  10. #include <intuition/imageclass.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <libraries/gadtools.h>
  13. #include <graphics/displayinfo.h>
  14. #include <graphics/gfxbase.h>
  15. #include <reqtools/reqtools.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/gadtools_protos.h>
  19. #include <clib/graphics_protos.h>
  20. #include <clib/utility_protos.h>
  21. #include <string.h>
  22. #include <clib/diskfont_protos.h>
  23.  
  24. #include "SetAlarm.h"
  25.  
  26.  
  27. int SetHours, SetMinutes, SetSeconds;
  28.  
  29. struct Window         *SetAlarmWnd = NULL;
  30. struct Gadget         *SetAlarmGList = NULL;
  31. struct Gadget         *SetAlarmGadgets[5];
  32. UWORD                  SetAlarmLeft = 101;
  33. UWORD                  SetAlarmTop = 60;
  34. UWORD                  SetAlarmWidth = 214;
  35. UWORD                  SetAlarmHeight = 92;
  36. UBYTE                 *SetAlarmWdt = NULL;
  37.  
  38. UWORD SetAlarmGTypes[] = {
  39.      SLIDER_KIND,
  40.      SLIDER_KIND,
  41.      SLIDER_KIND,
  42.      BUTTON_KIND,
  43.      BUTTON_KIND
  44. };
  45.  
  46. struct NewGadget SetAlarmNGad[] = {
  47.      77, 13, 101, 12, (UBYTE *)"Hours", NULL, GD_SetHours, PLACETEXT_LEFT ,NULL, NULL,
  48.      77, 29, 101, 12, (UBYTE *)"Minutes", NULL, GD_SetMinutes, PLACETEXT_LEFT ,NULL, NULL,
  49.      77, 45, 101, 12, (UBYTE *)"Seconds", NULL, GD_SetSeconds, PLACETEXT_LEFT ,NULL, NULL,
  50.      3, 71, 103, 17, (UBYTE *)"OK", NULL, GD_SetOK, PLACETEXT_IN ,NULL, NULL,
  51.      107, 71, 103, 17, (UBYTE *)"Cancel", NULL, GD_SetCancel, PLACETEXT_IN ,NULL, NULL
  52. };
  53.  
  54. ULONG SetAlarmGTags[] = {
  55.      (GTSL_Level), 0, (GTSL_Max), 23, (GA_RelVerify), TRUE, (GTSL_LevelFormat), (ULONG)"%2ld", 
  56.          (GTSL_MaxLevelLen), 2, (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ,
  57.          (GA_RelVerify), TRUE, (TAG_DONE),
  58.      (GTSL_Level), 0, (GTSL_Max), 59, (GA_RelVerify), TRUE, (GTSL_LevelFormat), (ULONG)"%2ld",
  59.          (GTSL_MaxLevelLen), 2, (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ,
  60.          (GA_RelVerify), TRUE, (TAG_DONE),
  61.      (GTSL_Level), 0, (GTSL_Max), 59, (GA_RelVerify), TRUE, (GTSL_LevelFormat), (ULONG)"%2ld", 
  62.          (GTSL_MaxLevelLen), 2, (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ,
  63.          (GA_RelVerify), TRUE, (TAG_DONE),
  64.      (TAG_DONE),
  65.      (TAG_DONE)
  66. };
  67.  
  68. UWORD             DriPens[] = {
  69.      ~0 };
  70.  
  71.  
  72. void SetAlarmRender( void )
  73. {
  74.      UWORD        offx, offy;
  75.  
  76.      offx = SetAlarmWnd->BorderLeft;
  77.      offy = SetAlarmWnd->BorderTop;
  78.  
  79.  
  80.      DrawBevelBox( SetAlarmWnd->RPort, offx + 2, offy + 70, 209, 19, GT_VisualInfo, VisualInfo, TAG_DONE );
  81.      DrawBevelBox( SetAlarmWnd->RPort, offx + 0, offy + 70, 213, 21, GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  82.      DrawBevelBox( SetAlarmWnd->RPort, offx + 2, offy + 1, 209, 68, GT_VisualInfo, VisualInfo, TAG_DONE );
  83.      DrawBevelBox( SetAlarmWnd->RPort, offx + 0, offy + 0, 213, 70, GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  84. }
  85.  
  86. int OpenSetAlarmWindow(char *title)
  87. {
  88.      struct NewGadget     ng;
  89.      struct Gadget       *g;
  90.      UWORD                lc, tc;
  91.      UWORD                offx = Scr->WBorLeft,offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  92.  
  93.      SetAlarmGTags[1] = SetHours;
  94.      SetAlarmGTags[18] = SetMinutes;
  95.      SetAlarmGTags[35] = SetSeconds;
  96.  
  97.      if ( ! ( g = CreateContext( &SetAlarmGList )))
  98.           return( 1L );
  99.  
  100.      for( lc = 0, tc = 0; lc < SetAlarm_CNT; lc++ ) {
  101.  
  102.           CopyMem((char * )&SetAlarmNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  103.  
  104.           ng.ng_VisualInfo = VisualInfo;
  105.           ng.ng_TextAttr   = &topaz8;
  106.           ng.ng_LeftEdge  += offx;
  107.           ng.ng_TopEdge   += offy;
  108.  
  109.           SetAlarmGadgets[ lc ] = g = CreateGadgetA((ULONG)SetAlarmGTypes[ lc ], g, &ng, ( struct TagItem * )&SetAlarmGTags[ tc ] );
  110.  
  111.           while( SetAlarmGTags[ tc ] ) tc += 2;
  112.           tc++;
  113.  
  114.           if ( NOT g )
  115.           return( 2L );
  116.      }
  117.  
  118.      if ( ! ( SetAlarmWnd = OpenWindowTags( NULL,
  119.                           WA_Left,          SetAlarmLeft,
  120.                           WA_Top,           SetAlarmTop,
  121.                           WA_InnerWidth,    SetAlarmWidth,
  122.                           WA_InnerHeight,   SetAlarmHeight,
  123.                           WA_IDCMP,         IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_GADGETUP|IDCMP_MOUSEMOVE|IDCMP_GADGETDOWN,
  124.                           WA_Flags,         WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
  125.                           WA_Gadgets,       SetAlarmGList,
  126.                           WA_Title,         title,
  127.                           WA_ScreenTitle,   "DClock V1.6 © 1995",
  128.                           WA_CustomScreen,  Scr,
  129.                           TAG_DONE )))
  130.           return( 4L );
  131.  
  132.      GT_RefreshWindow( SetAlarmWnd, NULL );
  133.  
  134.      SetAlarmRender();
  135.  
  136.      return( 0L );
  137. }
  138.  
  139. void CloseSetAlarmWindow( void )
  140. {
  141.      if ( SetAlarmWnd        ) {
  142.           CloseWindow( SetAlarmWnd );
  143.           SetAlarmWnd = NULL;
  144.      }
  145.  
  146.      if ( SetAlarmGList      ) {
  147.           FreeGadgets( SetAlarmGList );
  148.           SetAlarmGList = NULL;
  149.      }
  150. }
  151.  
  152.  
  153. int SetAlarm(int type, int preset)
  154. {
  155.     int timeval = SET_CANCEL;
  156.  
  157.     SetHours = preset / 10000;
  158.     SetMinutes = (preset - SetHours * 10000) / 100;
  159.     SetSeconds = (preset - SetHours * 10000 - SetMinutes * 100);
  160.  
  161.     switch (type)
  162.     {
  163.         case SET_ALARM:
  164.               OpenSetAlarmWindow("Set alarm");
  165.               break;
  166.         case SET_TIMER:
  167.               OpenSetAlarmWindow("Set timer");
  168.               break;
  169.         default:
  170.               OpenSetAlarmWindow(NULL);
  171.               break;
  172.     }
  173.  
  174.     if (SetAlarmWnd)
  175.     {
  176.         if (SetAlarmEventLoop())
  177.         {
  178.             timeval = SetHours * 10000 + SetMinutes * 100 + SetSeconds;
  179.         }
  180.         CloseSetAlarmWindow();
  181.         
  182.     }
  183.     else
  184.         rtEZRequestA("ERROR: Can't open window\n"
  185.                          "Close another application to free memory\n",
  186.                          "Oops", NULL, NULL, NULL);
  187.  
  188.     return timeval;
  189. }
  190.  
  191. BOOL SetAlarmEventLoop(void)
  192. {
  193.     struct IntuiMessage *msg;
  194.     BOOL done = FALSE;
  195.     ULONG Class;
  196.     UWORD Code;
  197.     ULONG windowSig = 1L << SetAlarmWnd->UserPort->mp_SigBit;
  198.     struct Gadget *gad;
  199.     BOOL ret = FALSE;
  200.  
  201.     while (! done)
  202.     {
  203.         Wait(windowSig);
  204.  
  205.         while ((! done) && (msg = GT_GetIMsg(SetAlarmWnd->UserPort)))
  206.         {
  207.             Class = msg->Class;
  208.             Code = msg->Code;
  209.             GT_ReplyIMsg(msg);
  210.             switch (Class)
  211.             {
  212.                 case IDCMP_CLOSEWINDOW:
  213.                       done = TRUE;
  214.                       break;
  215.                 case IDCMP_GADGETUP:
  216.                       gad = (struct Gadget *)msg->IAddress;
  217.                       switch (gad->GadgetID)
  218.                       {
  219.                           case GD_SetHours:
  220.                                  SetHours = Code;
  221.                                  break;
  222.                           case GD_SetMinutes:
  223.                                  SetMinutes = Code;
  224.                                  break;
  225.                           case GD_SetSeconds:
  226.                                  SetSeconds = Code;
  227.                                  break;
  228.                           case GD_SetOK:
  229.                                  ret = TRUE;
  230.                           case GD_SetCancel:
  231.                                  done = TRUE;
  232.                                  break;
  233.                       }
  234.                       break;
  235.             }
  236.         }
  237.     }
  238.     return ret;
  239. }
  240.  
  241.