home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d945 / reminder.lha / Reminder / src / src.lha / RemSAS.c < prev    next >
C/C++ Source or Header  |  1993-04-19  |  13KB  |  396 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Matti Rintala
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include <pragmas/exec_pragmas.h>
  26. #include <pragmas/intuition_pragmas.h>
  27. #include <pragmas/gadtools_pragmas.h>
  28. #include <pragmas/graphics_pragmas.h>
  29. #include <pragmas/utility_pragmas.h>
  30.  
  31. #include "RemSAS.h"
  32.  
  33. struct Screen         *Scr = NULL;
  34. UBYTE                 *PubScreenName = "Workbench";
  35. APTR                   VisualInfo = NULL;
  36. struct Window         *MainWnd = NULL;
  37. struct Gadget         *MainGList = NULL;
  38. struct IntuiMessage    MainMsg;
  39. struct Gadget         *MainGadgets[21];
  40. UWORD                  MainLeft = 0;
  41. UWORD                  MainTop = 0;
  42. UWORD                  MainWidth = 632;
  43. UWORD                  MainHeight = 187;
  44. UBYTE                 *MainWdt = (UBYTE *)"Reminder V1.20 © 1993 Matti Rintala";
  45. struct TextAttr       *Font, Attr;
  46. UWORD                  FontX, FontY;
  47. UWORD                  OffX, OffY;
  48. struct TextFont       *MainFont = NULL;
  49.  
  50. UBYTE *ARexxMode0Labels[] = {
  51.     (UBYTE *)"Not_hing",
  52.     (UBYTE *)"Scr_ipt",
  53.     (UBYTE *)"_Command",
  54.     NULL };
  55.  
  56. extern struct MinList Weekday0List;
  57.  
  58. struct Node Weekday0Nodes[] = {
  59.     &Weekday0Nodes[1], ( struct Node * )&Weekday0List.mlh_Head, 0, 0, "Monday",
  60.     &Weekday0Nodes[2], &Weekday0Nodes[0], 0, 0, "Tuesday",
  61.     &Weekday0Nodes[3], &Weekday0Nodes[1], 0, 0, "Wednesday",
  62.     &Weekday0Nodes[4], &Weekday0Nodes[2], 0, 0, "Thursday",
  63.     &Weekday0Nodes[5], &Weekday0Nodes[3], 0, 0, "Friday",
  64.     &Weekday0Nodes[6], &Weekday0Nodes[4], 0, 0, "Saturday",
  65.     &Weekday0Nodes[7], &Weekday0Nodes[5], 0, 0, "Sunday",
  66.     ( struct Node * )&Weekday0List.mlh_Tail, &Weekday0Nodes[6], 0, 0, "ANY" };
  67.  
  68. struct MinList Weekday0List = {
  69.     ( struct MinNode * )&Weekday0Nodes[0], ( struct MinNode * )NULL, ( struct MinNode * )&Weekday0Nodes[7] };
  70.  
  71. extern struct MinList MonthList0List;
  72.  
  73. struct Node MonthList0Nodes[] = {
  74.     &MonthList0Nodes[1], ( struct Node * )&MonthList0List.mlh_Head, 0, 0, "January",
  75.     &MonthList0Nodes[2], &MonthList0Nodes[0], 0, 0, "February",
  76.     &MonthList0Nodes[3], &MonthList0Nodes[1], 0, 0, "March",
  77.     &MonthList0Nodes[4], &MonthList0Nodes[2], 0, 0, "April",
  78.     &MonthList0Nodes[5], &MonthList0Nodes[3], 0, 0, "May",
  79.     &MonthList0Nodes[6], &MonthList0Nodes[4], 0, 0, "June",
  80.     &MonthList0Nodes[7], &MonthList0Nodes[5], 0, 0, "July",
  81.     &MonthList0Nodes[8], &MonthList0Nodes[6], 0, 0, "August",
  82.     &MonthList0Nodes[9], &MonthList0Nodes[7], 0, 0, "September",
  83.     &MonthList0Nodes[10], &MonthList0Nodes[8], 0, 0, "October",
  84.     &MonthList0Nodes[11], &MonthList0Nodes[9], 0, 0, "November",
  85.     &MonthList0Nodes[12], &MonthList0Nodes[10], 0, 0, "December",
  86.     ( struct Node * )&MonthList0List.mlh_Tail, &MonthList0Nodes[11], 0, 0, "ANY" };
  87.  
  88. struct MinList MonthList0List = {
  89.     ( struct MinNode * )&MonthList0Nodes[0], ( struct MinNode * )NULL, ( struct MinNode * )&MonthList0Nodes[12] };
  90.  
  91. struct IntuiText MainIText[] = {
  92.     2, 0, JAM1,487, 53, NULL, (UBYTE *)"Remind # days before and after:", NULL,
  93.     2, 0, JAM1,451, 94, NULL, (UBYTE *)"Date of event:", NULL,
  94.     2, 0, JAM1,425, 10, NULL, (UBYTE *)"ARexx:", NULL };
  95.  
  96. #define Main_TNUM 3
  97.  
  98. UWORD MainGTypes[] = {
  99.     LISTVIEW_KIND,
  100.     CHECKBOX_KIND,
  101.     LISTVIEW_KIND,
  102.     BUTTON_KIND,
  103.     BUTTON_KIND,
  104.     BUTTON_KIND,
  105.     BUTTON_KIND,
  106.     BUTTON_KIND,
  107.     TEXT_KIND,
  108.     MX_KIND,
  109.     BUTTON_KIND,
  110.     STRING_KIND,
  111.     LISTVIEW_KIND,
  112.     INTEGER_KIND,
  113.     INTEGER_KIND,
  114.     INTEGER_KIND,
  115.     STRING_KIND,
  116.     STRING_KIND,
  117.     STRING_KIND,
  118.     INTEGER_KIND,
  119.     CHECKBOX_KIND
  120. };
  121.  
  122. struct NewGadget MainNGad[] = {
  123.     286, 99, 105, 56, (UBYTE *)"_Weekday", NULL, GD_Weekday, PLACETEXT_BELOW, NULL, (APTR)WeekdayClicked,
  124.     571, 73, 26, 11, (UBYTE *)"D_elete event when acked", NULL, GD_Autodelete, PLACETEXT_LEFT, NULL, (APTR)AutodeleteClicked,
  125.     8, 15, 264, 112, (UBYTE *)"E_vents in memory:", NULL, GD_Eventlist, PLACETEXT_ABOVE|NG_HIGHLABEL, NULL, (APTR)EventlistClicked,
  126.     76, 130, 60, 13, (UBYTE *)"_Add", NULL, GD_Add, PLACETEXT_IN, NULL, (APTR)AddClicked,
  127.     144, 130, 60, 13, (UBYTE *)"_Remove", NULL, GD_Remove, PLACETEXT_IN, NULL, (APTR)RemoveClicked,
  128.     212, 130, 60, 13, (UBYTE *)"_Update", NULL, GD_Update, PLACETEXT_IN, NULL, (APTR)UpdateClicked,
  129.     16, 151, 117, 13, (UBYTE *)"_Quit, no save", NULL, GD_Cancel, PLACETEXT_IN, NULL, (APTR)CancelClicked,
  130.     148, 151, 117, 13, (UBYTE *)"Quit and _save", NULL, GD_Quit, PLACETEXT_IN, NULL, (APTR)QuitClicked,
  131.     395, 127, 41, 13, NULL, NULL, GD_ShowWDay, 0, NULL, NULL,
  132.     288, 11, 17, 9, NULL, NULL, GD_ARexxMode, PLACETEXT_RIGHT, NULL, (APTR)ARexxModeClicked,
  133.     8, 130, 60, 13, (UBYTE *)"_New", NULL, GD_New, PLACETEXT_IN, NULL, (APTR)NewClicked,
  134.     440, 139, 105, 13, (UBYTE *)"_Month", NULL, GD_Month, PLACETEXT_BELOW, NULL, (APTR)MonthClicked,
  135.     440, 98, 105, 56, NULL, NULL, GD_MonthList, 0, NULL, (APTR)MonthListClicked,
  136.     549, 142, 60, 13, (UBYTE *)"_Year", NULL, GD_Year, PLACETEXT_BELOW, NULL, (APTR)YearClicked,
  137.     419, 58, 54, 13, (UBYTE *)"_Before", NULL, GD_Before, PLACETEXT_LEFT, NULL, (APTR)BeforeClicked,
  138.     555, 58, 54, 13, (UBYTE *)"A_fter", NULL, GD_After, PLACETEXT_LEFT, NULL, (APTR)AfterClicked,
  139.     50, 170, 569, 13, (UBYTE *)"_Text", NULL, GD_Text, PLACETEXT_LEFT, NULL, (APTR)TextClicked,
  140.     381, 21, 231, 12, (UBYTE *)"C_omm/Script", NULL, GD_ARexxCom, PLACETEXT_BELOW, NULL, (APTR)ARexxComClicked,
  141.     512, 7, 100, 12, (UBYTE *)"_Port", NULL, GD_ARexxPort, PLACETEXT_LEFT, NULL, (APTR)ARexxPortClicked,
  142.     396, 142, 41, 13, (UBYTE *)"_Day", NULL, GD_Day, PLACETEXT_BELOW, NULL, (APTR)DayClicked,
  143.     304, 60, 26, 11, (UBYTE *)"_Grouped", NULL, GD_Grouped, PLACETEXT_BELOW, NULL, (APTR)GroupedClicked
  144. };
  145.  
  146. ULONG MainGTags[] = {
  147.     (GTLV_Labels), (ULONG)&Weekday0List, (GTLV_ShowSelected), NULL, (GT_Underscore), '_', (TAG_DONE),
  148.     (GT_Underscore), '_', (TAG_DONE),
  149.     (GTLV_ShowSelected), NULL, (GT_Underscore), '_', (TAG_DONE),
  150.     (GT_Underscore), '_', (TAG_DONE),
  151.     (GT_Underscore), '_', (TAG_DONE),
  152.     (GT_Underscore), '_', (TAG_DONE),
  153.     (GT_Underscore), '_', (TAG_DONE),
  154.     (GT_Underscore), '_', (TAG_DONE),
  155.     (GTTX_Border), TRUE, (TAG_DONE),
  156.     (GTMX_Labels), (ULONG)&ARexxMode0Labels[ 0 ], (GT_Underscore), '_', (TAG_DONE),
  157.     (GT_Underscore), '_', (TAG_DONE),
  158.     (GTST_String), (ULONG)"January", (GTST_MaxChars), 9, (GT_Underscore), '_', (TAG_DONE),
  159.     (GTLV_Labels), (ULONG)&MonthList0List, (GTLV_ShowSelected), 1L, (TAG_DONE),
  160.     (GTIN_Number), 0, (GTIN_MaxChars), 4, (GT_Underscore), '_', (TAG_DONE),
  161.     (GTIN_Number), 0, (GTIN_MaxChars), 3, (GT_Underscore), '_', (TAG_DONE),
  162.     (GTIN_Number), 0, (GTIN_MaxChars), 3, (GT_Underscore), '_', (TAG_DONE),
  163.     (GTST_MaxChars), 90, (STRINGA_Justification), (GACT_STRINGCENTER), (GT_Underscore), '_', (TAG_DONE),
  164.     (GTST_MaxChars), 28, (GT_Underscore), '_', (TAG_DONE),
  165.     (GTST_MaxChars), 10, (GT_Underscore), '_', (TAG_DONE),
  166.     (GTIN_Number), 0, (GTIN_MaxChars), 2, (GT_Underscore), '_', (TAG_DONE),
  167.     (GT_Underscore), '_', (TAG_DONE)
  168. };
  169.  
  170. static UWORD ComputeX( UWORD value )
  171. {
  172.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  173. }
  174.  
  175. static UWORD ComputeY( UWORD value )
  176. {
  177.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  178. }
  179.  
  180. static void ComputeFont( UWORD width, UWORD height )
  181. {
  182.     Forbid();
  183.     Font = &Attr;
  184.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  185.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  186.     FontX = GfxBase->DefaultFont->tf_XSize;
  187.     Permit();
  188.  
  189.     OffX = Scr->WBorLeft;
  190.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  191.  
  192.     if ( width && height ) {
  193.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  194.             goto UseTopaz;
  195.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  196.             goto UseTopaz;
  197.     }
  198.     return;
  199.  
  200. UseTopaz:
  201.     Font->ta_Name = (STRPTR)"topaz.font";
  202.     FontX = FontY = Font->ta_YSize = 8;
  203. }
  204.  
  205. int SetupScreen( void )
  206. {
  207.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  208.         return( 1L );
  209.  
  210.     ComputeFont( 0, 0 );
  211.  
  212.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  213.         return( 2L );
  214.  
  215.     return( 0L );
  216. }
  217.  
  218. void CloseDownScreen( void )
  219. {
  220.     if ( VisualInfo ) {
  221.         FreeVisualInfo( VisualInfo );
  222.         VisualInfo = NULL;
  223.     }
  224.  
  225.     if ( Scr        ) {
  226.         UnlockPubScreen( NULL, Scr );
  227.         Scr = NULL;
  228.     }
  229. }
  230.  
  231. void MainRender( void )
  232. {
  233.     struct IntuiText    it;
  234.     UWORD            cnt;
  235.  
  236.     ComputeFont( MainWidth, MainHeight );
  237.  
  238.     DrawBevelBox( MainWnd->RPort, OffX + ComputeX( 9 ),
  239.                     OffY + ComputeY( 147 ),
  240.                     ComputeX( 264 ),
  241.                     ComputeY( 21 ),
  242.                     GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  243.     DrawBevelBox( MainWnd->RPort, OffX + ComputeX( 278 ),
  244.                     OffY + ComputeY( 4 ),
  245.                     ComputeX( 341 ),
  246.                     ComputeY( 41 ),
  247.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  248.     DrawBevelBox( MainWnd->RPort, OffX + ComputeX( 278 ),
  249.                     OffY + ComputeY( 47 ),
  250.                     ComputeX( 341 ),
  251.                     ComputeY( 39 ),
  252.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  253.     DrawBevelBox( MainWnd->RPort, OffX + ComputeX( 278 ),
  254.                     OffY + ComputeY( 88 ),
  255.                     ComputeX( 341 ),
  256.                     ComputeY( 80 ),
  257.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  258.  
  259.     for ( cnt = 0; cnt < Main_TNUM; cnt++ ) {
  260.         CopyMem(( char * )&MainIText[ cnt ], ( char * )&it, (long)sizeof( struct IntuiText ));
  261.         it.ITextFont = Font;
  262.         it.LeftEdge  = OffX + ComputeX( it.LeftEdge ) - ( IntuiTextLength( &it ) >> 1 );
  263.         it.TopEdge   = OffY + ComputeY( it.TopEdge ) - ( Font->ta_YSize >> 1 );
  264.         PrintIText( MainWnd->RPort, &it, 0, 0 );
  265.     }
  266. }
  267.  
  268. int HandleMainIDCMP( void )
  269. {
  270.     struct IntuiMessage    *m;
  271.     int            (*func)();
  272.     BOOL            running = TRUE;
  273.  
  274.     while( m = GT_GetIMsg( MainWnd->UserPort )) {
  275.  
  276.         CopyMem(( char * )m, ( char * )&MainMsg, (long)sizeof( struct IntuiMessage ));
  277.  
  278.         GT_ReplyIMsg( m );
  279.  
  280.         switch ( MainMsg.Class ) {
  281.  
  282.             case    IDCMP_REFRESHWINDOW:
  283.                 GT_BeginRefresh( MainWnd );
  284.                 MainRender();
  285.                 GT_EndRefresh( MainWnd, TRUE );
  286.                 break;
  287.  
  288.             case    IDCMP_CLOSEWINDOW:
  289.                 running = MainCloseWindow();
  290.                 break;
  291.  
  292.             case    IDCMP_VANILLAKEY:
  293.                 running = MainVanillaKey();
  294.                 break;
  295.  
  296.             case    IDCMP_RAWKEY:
  297.                 running = MainRawKey();
  298.                 break;
  299.  
  300.             case    IDCMP_GADGETUP:
  301.             case    IDCMP_GADGETDOWN:
  302.                 func = ( void * )(( struct Gadget * )MainMsg.IAddress )->UserData;
  303.                 running = func();
  304.                 break;
  305.         }
  306.     }
  307.     return( running );
  308. }
  309.  
  310. int OpenMainWindow( void )
  311. {
  312.     struct NewGadget    ng;
  313.     struct Gadget    *g;
  314.     struct TagItem    *tmp;
  315.     UWORD        lc, tc;
  316.     UWORD        wleft = MainLeft, wtop = MainTop, ww, wh;
  317.  
  318.     ComputeFont( MainWidth, MainHeight );
  319.  
  320.     ww = ComputeX( MainWidth );
  321.     wh = ComputeY( MainHeight );
  322.  
  323.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  324.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  325.  
  326.     if ( ! ( MainFont = OpenDiskFont( Font )))
  327.         return( 5L );
  328.  
  329.     if ( ! ( g = CreateContext( &MainGList )))
  330.         return( 1L );
  331.  
  332.     for( lc = 0, tc = 0; lc < Main_CNT; lc++ ) {
  333.  
  334.         CopyMem((char * )&MainNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  335.  
  336.         ng.ng_VisualInfo = VisualInfo;
  337.         ng.ng_TextAttr   = Font;
  338.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  339.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  340.         ng.ng_Width      = ComputeX( ng.ng_Width );
  341.         ng.ng_Height     = ComputeY( ng.ng_Height);
  342.  
  343.         if ( MainGTypes[ lc ] == LISTVIEW_KIND ) {
  344.             if ( tmp = FindTagItem( GTLV_ShowSelected, ( struct TagItem * )&MainGTags[ tc ] )) {
  345.                 if ( tmp->ti_Data ) tmp->ti_Data = (ULONG)g;
  346.             }
  347.         }
  348.  
  349.         MainGadgets[ lc ] = g = CreateGadgetA((ULONG)MainGTypes[ lc ], g, &ng, ( struct TagItem * )&MainGTags[ tc ] );
  350.  
  351.         while( MainGTags[ tc ] ) tc += 2;
  352.         tc++;
  353.  
  354.         if ( NOT g )
  355.             return( 2L );
  356.     }
  357.  
  358.     if ( ! ( MainWnd = OpenWindowTags( NULL,
  359.                 WA_Left,    wleft,
  360.                 WA_Top,        wtop,
  361.                 WA_Width,    ww + OffX + Scr->WBorRight,
  362.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  363.                 WA_IDCMP,    LISTVIEWIDCMP|CHECKBOXIDCMP|BUTTONIDCMP|TEXTIDCMP|MXIDCMP|STRINGIDCMP|INTEGERIDCMP|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  364.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  365.                 WA_Gadgets,    MainGList,
  366.                 WA_Title,    MainWdt,
  367.                 WA_ScreenTitle,    "Reminder V1.20 © 1993 Matti Rintala",
  368.                 TAG_DONE )))
  369.     return( 4L );
  370.  
  371.     GT_RefreshWindow( MainWnd, NULL );
  372.  
  373.     MainRender();
  374.  
  375.     return( 0L );
  376. }
  377.  
  378. void CloseMainWindow( void )
  379. {
  380.     if ( MainWnd        ) {
  381.         CloseWindow( MainWnd );
  382.         MainWnd = NULL;
  383.     }
  384.  
  385.     if ( MainGList      ) {
  386.         FreeGadgets( MainGList );
  387.         MainGList = NULL;
  388.     }
  389.  
  390.     if ( MainFont ) {
  391.         CloseFont( MainFont );
  392.         MainFont = NULL;
  393.     }
  394. }
  395.  
  396.