home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / gblanker3.5.src.lha / GSource / Blankers / Executor / Executor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-07  |  6.0 KB  |  240 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Michael D. Bayne
  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 "Executor.h"
  26.  
  27. struct Screen         *Scr = NULL;
  28. UBYTE                 *PubScreenName = NULL;
  29. APTR                   VisualInfo = NULL;
  30. struct Window         *ExecutorWnd = NULL;
  31. struct Gadget         *ExecutorGList = NULL;
  32. struct IntuiMessage    ExecutorMsg;
  33. struct Gadget         *ExecutorGadgets[5];
  34. UWORD                  ExecutorLeft = 0;
  35. UWORD                  ExecutorTop = 12;
  36. UWORD                  ExecutorWidth = 190;
  37. UWORD                  ExecutorHeight = 59;
  38. UBYTE                 *ExecutorWdt = (UBYTE *)"Executor Prefs";
  39. struct TextAttr       *Font, Attr;
  40. UWORD                  FontX, FontY;
  41. UWORD                  OffX, OffY;
  42. struct TextFont       *ExecutorFont = NULL;
  43.  
  44. UWORD ExecutorGTypes[] = {
  45.     BUTTON_KIND,
  46.     BUTTON_KIND,
  47.     BUTTON_KIND,
  48.     STRING_KIND,
  49.     STRING_KIND
  50. };
  51.  
  52. struct NewGadget ExecutorNGad[] = {
  53.     4, 42, 58, 14, (UBYTE *)"_Save", NULL, GD_BT_SAVE, PLACETEXT_IN, NULL, (APTR)BT_SAVEClicked,
  54.     128, 42, 58, 14, (UBYTE *)"_Cancel", NULL, GD_BT_CANCEL, PLACETEXT_IN, NULL, (APTR)BT_CANCELClicked,
  55.     66, 42, 58, 14, (UBYTE *)"_Test", NULL, GD_BT_TEST, PLACETEXT_IN, NULL, (APTR)BT_TESTClicked,
  56.     55, 4, 131, 15, (UBYTE *)"St_artup", NULL, GD_ST_START, PLACETEXT_LEFT, NULL, (APTR)ST_STARTClicked,
  57.     55, 23, 131, 15, (UBYTE *)"_Kill", NULL, GD_ST_KILL, PLACETEXT_LEFT, NULL, (APTR)ST_KILLClicked
  58. };
  59.  
  60. ULONG ExecutorGTags[] = {
  61.     (GT_Underscore), '_', (TAG_DONE),
  62.     (GT_Underscore), '_', (TAG_DONE),
  63.     (GT_Underscore), '_', (TAG_DONE),
  64.     (GTST_MaxChars), 128, (GT_Underscore), '_', (TAG_DONE),
  65.     (GTST_MaxChars), 128, (GT_Underscore), '_', (TAG_DONE)
  66. };
  67.  
  68. static UWORD ComputeX( UWORD value )
  69. {
  70.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  71. }
  72.  
  73. static UWORD ComputeY( UWORD value )
  74. {
  75.     return(( UWORD )((( FontY * value ) + 4 ) / 9 ));
  76. }
  77.  
  78. static void ComputeFont( UWORD width, UWORD height )
  79. {
  80.     Forbid();
  81.     Font = &Attr;
  82.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  83.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  84.     FontX = GfxBase->DefaultFont->tf_XSize;
  85.     Permit();
  86.  
  87.     OffX = Scr->WBorLeft;
  88.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  89.  
  90.     if ( width && height ) {
  91.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  92.             goto UseTopaz;
  93.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  94.             goto UseTopaz;
  95.     }
  96.     return;
  97.  
  98. UseTopaz:
  99.     Font->ta_Name = (STRPTR)"topaz.font";
  100.     FontX = FontY = Font->ta_YSize = 8;
  101. }
  102.  
  103. int SetupScreen( void )
  104. {
  105.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  106.         return( 1L );
  107.  
  108.     ComputeFont( 0, 0 );
  109.  
  110.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  111.         return( 2L );
  112.  
  113.     return( 0L );
  114. }
  115.  
  116. void CloseDownScreen( void )
  117. {
  118.     if ( VisualInfo ) {
  119.         FreeVisualInfo( VisualInfo );
  120.         VisualInfo = NULL;
  121.     }
  122.  
  123.     if ( Scr        ) {
  124.         UnlockPubScreen( NULL, Scr );
  125.         Scr = NULL;
  126.     }
  127. }
  128.  
  129. int HandleExecutorIDCMP( void )
  130. {
  131.     struct IntuiMessage    *m;
  132.     int            (*func)();
  133.     BOOL            running = TRUE;
  134.  
  135.     while( m = GT_GetIMsg( ExecutorWnd->UserPort )) {
  136.  
  137.         CopyMem(( char * )m, ( char * )&ExecutorMsg, (long)sizeof( struct IntuiMessage ));
  138.  
  139.         GT_ReplyIMsg( m );
  140.  
  141.         switch ( ExecutorMsg.Class ) {
  142.  
  143.             case    IDCMP_REFRESHWINDOW:
  144.                 GT_BeginRefresh( ExecutorWnd );
  145.                 GT_EndRefresh( ExecutorWnd, TRUE );
  146.                 break;
  147.  
  148.             case    IDCMP_VANILLAKEY:
  149.                 running = ExecutorVanillaKey();
  150.                 break;
  151.  
  152.             case    IDCMP_GADGETUP:
  153.             case    IDCMP_GADGETDOWN:
  154.                 func = ( void * )(( struct Gadget * )ExecutorMsg.IAddress )->UserData;
  155.                 running = func();
  156.                 break;
  157.         }
  158.     }
  159.     return( running );
  160. }
  161.  
  162. int OpenExecutorWindow( void )
  163. {
  164.     struct NewGadget    ng;
  165.     struct Gadget    *g;
  166.     UWORD        lc, tc;
  167.     UWORD        wleft = ExecutorLeft, wtop = ExecutorTop, ww, wh;
  168.  
  169.     ComputeFont( ExecutorWidth, ExecutorHeight );
  170.  
  171.     ww = ComputeX( ExecutorWidth );
  172.     wh = ComputeY( ExecutorHeight );
  173.  
  174.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  175.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  176.  
  177.     if ( ! ( ExecutorFont = OpenDiskFont( Font )))
  178.         return( 5L );
  179.  
  180.     if ( ! ( g = CreateContext( &ExecutorGList )))
  181.         return( 1L );
  182.  
  183.     for( lc = 0, tc = 0; lc < Executor_CNT; lc++ ) {
  184.  
  185.         CopyMem((char * )&ExecutorNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  186.  
  187.         ng.ng_VisualInfo = VisualInfo;
  188.         ng.ng_TextAttr   = Font;
  189.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  190.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  191.         ng.ng_Width      = ComputeX( ng.ng_Width );
  192.         ng.ng_Height     = ComputeY( ng.ng_Height);
  193.  
  194.         ExecutorGadgets[ lc ] = g = CreateGadgetA((ULONG)ExecutorGTypes[ lc ], g, &ng, ( struct TagItem * )&ExecutorGTags[ tc ] );
  195.  
  196.         while( ExecutorGTags[ tc ] ) tc += 2;
  197.         tc++;
  198.  
  199.         if ( NOT g )
  200.             return( 2L );
  201.     }
  202.  
  203.     if ( ! ( ExecutorWnd = OpenWindowTags( NULL,
  204.                 WA_Left,    wleft,
  205.                 WA_Top,        wtop,
  206.                 WA_Width,    ww + OffX + Scr->WBorRight,
  207.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  208.                 WA_IDCMP,    BUTTONIDCMP|STRINGIDCMP|IDCMP_GADGETDOWN|IDCMP_MOUSEMOVE|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  209.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  210.                 WA_Gadgets,    ExecutorGList,
  211.                 WA_Title,    ExecutorWdt,
  212.                 WA_ScreenTitle,    "Executor Prefs",
  213.                 WA_PubScreen,    Scr,
  214.                 TAG_DONE )))
  215.     return( 4L );
  216.  
  217.     GT_RefreshWindow( ExecutorWnd, NULL );
  218.  
  219.     return( 0L );
  220. }
  221.  
  222. void CloseExecutorWindow( void )
  223. {
  224.     if ( ExecutorWnd        ) {
  225.         CloseWindow( ExecutorWnd );
  226.         ExecutorWnd = NULL;
  227.     }
  228.  
  229.     if ( ExecutorGList      ) {
  230.         FreeGadgets( ExecutorGList );
  231.         ExecutorGList = NULL;
  232.     }
  233.  
  234.     if ( ExecutorFont ) {
  235.         CloseFont( ExecutorFont );
  236.         ExecutorFont = NULL;
  237.     }
  238. }
  239.  
  240.