home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 110 / af110sub.adf / DTConvert.lzx / DTConvert / gui.c < prev    next >
C/C++ Source or Header  |  2004-10-02  |  10KB  |  308 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Roland Mainz, GISBURN@W-Specht.rhein-ruhr.de
  6.  */
  7.  
  8. #include "DTConvert.h"
  9. #include "gui.h"
  10.  
  11. struct Screen         *Scr = NULL;
  12. UBYTE                 *PubScreenName = NULL;
  13. APTR                   VisualInfo = NULL;
  14. struct Window         *DTConvert_MAINWnd = NULL;
  15. struct Window         *DTConvert_DATATYPEWnd = NULL;
  16. struct Gadget         *DTConvert_MAINGList = NULL;
  17. struct Gadget         *DTConvert_DATATYPEGList = NULL;
  18. UWORD                  DTConvert_MAINZoom[4];
  19. UWORD                  DTConvert_DATATYPEZoom[4];
  20. struct Gadget         *DTConvert_MAINGadgets[8];
  21. struct Gadget         *DTConvert_DATATYPEGadgets[3];
  22. UWORD                  DTConvert_MAINLeft = 10;
  23. UWORD                  DTConvert_MAINTop = 15;
  24. UWORD                  DTConvert_MAINWidth = 476;
  25. UWORD                  DTConvert_MAINHeight = 82;
  26. UWORD                  DTConvert_DATATYPELeft = 47;
  27. UWORD                  DTConvert_DATATYPETop = 31;
  28. UWORD                  DTConvert_DATATYPEWidth = 379;
  29. UWORD                  DTConvert_DATATYPEHeight = 239;
  30. UBYTE                 *DTConvert_MAINWdt = (UBYTE *)"DTConvert";
  31. UBYTE                 *DTConvert_DATATYPEWdt = (UBYTE *)"Select DataType...";
  32. struct TextAttr       *Font, Attr;
  33. UWORD                  FontX, FontY;
  34. UWORD                  OffX, OffY;
  35.  
  36. UWORD DTConvert_MAINGTypes[] = {
  37.     STRING_KIND,
  38.     TEXT_KIND,
  39.     STRING_KIND,
  40.     BUTTON_KIND,
  41.     BUTTON_KIND,
  42.     BUTTON_KIND,
  43.     BUTTON_KIND,
  44.     BUTTON_KIND
  45. };
  46.  
  47. UWORD DTConvert_DATATYPEGTypes[] = {
  48.     LISTVIEW_KIND,
  49.     BUTTON_KIND,
  50.     BUTTON_KIND
  51. };
  52.  
  53. struct NewGadget DTConvert_MAINNGad[] = {
  54.     108, 9, 345, 13, (UBYTE *)"_Source", NULL, GD_SOURCE, PLACETEXT_LEFT, NULL, NULL,
  55.     108, 25, 345, 13, (UBYTE *)"DataType", NULL, GD_DATATYPE, PLACETEXT_LEFT, NULL, NULL,
  56.     108, 41, 345, 13, (UBYTE *)"_Destination", NULL, GD_DESTINATION, PLACETEXT_LEFT, NULL, NULL,
  57.     453, 9, 17, 13, (UBYTE *)"?", NULL, GD_GET_SOURCE, PLACETEXT_IN, NULL, NULL,
  58.     453, 25, 16, 13, (UBYTE *)"?", NULL, GD_GET_DATATYPE, PLACETEXT_IN, NULL, NULL,
  59.     453, 41, 16, 13, (UBYTE *)"?", NULL, GD_GET_DESTINATION, PLACETEXT_IN, NULL, NULL,
  60.     12, 65, 125, 13, (UBYTE *)"_Convert", NULL, GD_CONVERT, PLACETEXT_IN, NULL, NULL,
  61.     344, 65, 125, 13, (UBYTE *)"C_ancel", NULL, GD_CANCEL, PLACETEXT_IN, NULL, NULL
  62. };
  63.  
  64. struct NewGadget DTConvert_DATATYPENGad[] = {
  65.     10, 14, 363, 200, (UBYTE *)"_DataType", NULL, GD_DATATYPEDT, PLACETEXT_ABOVE, NULL, NULL,
  66.     10, 217, 101, 15, (UBYTE *)"_Ok", NULL, GD_OKDT, PLACETEXT_IN, NULL, NULL,
  67.     272, 217, 101, 15, (UBYTE *)"_Cancel", NULL, GD_CANCELDT, PLACETEXT_IN, NULL, NULL
  68. };
  69.  
  70. ULONG DTConvert_MAINGTags[] = {
  71.     (STRINGA_ExitHelp), TRUE, (GTST_MaxChars), 1024, (GT_Underscore), '_', (TAG_DONE),
  72.     (GTTX_Border), TRUE, (TAG_DONE),
  73.     (STRINGA_ExitHelp), TRUE, (GTST_MaxChars), 1024, (GT_Underscore), '_', (TAG_DONE),
  74.     (TAG_DONE),
  75.     (TAG_DONE),
  76.     (TAG_DONE),
  77.     (GT_Underscore), '_', (TAG_DONE),
  78.     (GT_Underscore), '_', (TAG_DONE)
  79. };
  80.  
  81. ULONG DTConvert_DATATYPEGTags[] = {
  82.     (GTLV_ShowSelected), NULL, (GT_Underscore), '_', (TAG_DONE),
  83.     (GT_Underscore), '_', (TAG_DONE),
  84.     (GT_Underscore), '_', (TAG_DONE)
  85. };
  86.  
  87. static UWORD ComputeX( UWORD value )
  88. {
  89.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  90. }
  91.  
  92. static UWORD ComputeY( UWORD value )
  93. {
  94.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  95. }
  96.  
  97. static void ComputeFont( UWORD width, UWORD height )
  98. {
  99.     Font = &Attr;
  100.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  101.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  102.     FontX = Scr->RastPort.Font->tf_XSize;
  103.  
  104.     OffX = Scr->WBorLeft;
  105.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  106.  
  107.     if ( width && height ) {
  108.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  109.             goto UseTopaz;
  110.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  111.             goto UseTopaz;
  112.     }
  113.     return;
  114.  
  115. UseTopaz:
  116.     Font->ta_Name = (STRPTR)"topaz.font";
  117.     FontX = FontY = Font->ta_YSize = 8;
  118. }
  119.  
  120. int SetupScreen( void )
  121. {
  122.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  123.         return( 1L );
  124.  
  125.     ComputeFont( 0, 0 );
  126.  
  127.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  128.         return( 2L );
  129.  
  130.     return( 0L );
  131. }
  132.  
  133. void CloseDownScreen( void )
  134. {
  135.     if ( VisualInfo ) {
  136.         FreeVisualInfo( VisualInfo );
  137.         VisualInfo = NULL;
  138.     }
  139.  
  140.     if ( Scr        ) {
  141.         UnlockPubScreen( NULL, Scr );
  142.         Scr = NULL;
  143.     }
  144. }
  145.  
  146. int OpenDTConvert_MAINWindow( void )
  147. {
  148.     struct NewGadget    ng;
  149.     struct Gadget    *g;
  150.     UWORD        lc, tc;
  151.     UWORD        wleft = DTConvert_MAINLeft, wtop = DTConvert_MAINTop, ww, wh;
  152.  
  153.     ComputeFont( DTConvert_MAINWidth, DTConvert_MAINHeight );
  154.  
  155.     ww = ComputeX( DTConvert_MAINWidth );
  156.     wh = ComputeY( DTConvert_MAINHeight );
  157.  
  158.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  159.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  160.  
  161.     if ( ! ( g = CreateContext( &DTConvert_MAINGList )))
  162.         return( 1L );
  163.  
  164.     for( lc = 0, tc = 0; lc < DTConvert_MAIN_CNT; lc++ ) {
  165.  
  166.         CopyMem((char * )&DTConvert_MAINNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  167.  
  168.         ng.ng_VisualInfo = VisualInfo;
  169.         ng.ng_TextAttr   = Font;
  170.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  171.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  172.         ng.ng_Width      = ComputeX( ng.ng_Width );
  173.         ng.ng_Height     = ComputeY( ng.ng_Height);
  174.  
  175.         DTConvert_MAINGadgets[ lc ] = g = CreateGadgetA((ULONG)DTConvert_MAINGTypes[ lc ], g, &ng, ( struct TagItem * )&DTConvert_MAINGTags[ tc ] );
  176.  
  177.         while( DTConvert_MAINGTags[ tc ] ) tc += 2;
  178.         tc++;
  179.  
  180.         if ( NOT g )
  181.             return( 2L );
  182.     }
  183.  
  184.     DTConvert_MAINZoom[0] = DTConvert_MAINLeft;
  185.     DTConvert_MAINZoom[1] = DTConvert_MAINTop;
  186.     if ( DTConvert_MAINWdt )
  187.         DTConvert_MAINZoom[2] = TextLength( &Scr->RastPort, (UBYTE *)DTConvert_MAINWdt, (ULONG)strlen((char *)DTConvert_MAINWdt )) + 80;
  188.     else
  189.         DTConvert_MAINZoom[2]  = 80L;
  190.         DTConvert_MAINZoom[3] = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  191.  
  192.     if ( ! ( DTConvert_MAINWnd = OpenWindowTags( NULL,
  193.                 WA_Left,    wleft,
  194.                 WA_Top,        wtop,
  195.                 WA_Width,    ww + OffX + Scr->WBorRight,
  196.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  197.                 WA_IDCMP,    STRINGIDCMP|TEXTIDCMP|BUTTONIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_VANILLAKEY|IDCMP_MENUHELP|IDCMP_REFRESHWINDOW,
  198.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_SIMPLE_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  199.                 WA_Gadgets,    DTConvert_MAINGList,
  200.                 WA_Title,    DTConvert_MAINWdt,
  201.                 WA_ScreenTitle,    "DTConvert",
  202.                 WA_PubScreen,    Scr,
  203.                 WA_Zoom,    DTConvert_MAINZoom,
  204.                 WA_AutoAdjust,    TRUE,
  205.                 WA_PubScreenFallBack,    TRUE,
  206.                 TAG_DONE )))
  207.     return( 4L );
  208.  
  209.     GT_RefreshWindow( DTConvert_MAINWnd, NULL );
  210.  
  211.     return( 0L );
  212. }
  213.  
  214. void CloseDTConvert_MAINWindow( void )
  215. {
  216.     if ( DTConvert_MAINWnd        ) {
  217.         CloseWindow( DTConvert_MAINWnd );
  218.         DTConvert_MAINWnd = NULL;
  219.     }
  220.  
  221.     if ( DTConvert_MAINGList      ) {
  222.         FreeGadgets( DTConvert_MAINGList );
  223.         DTConvert_MAINGList = NULL;
  224.     }
  225. }
  226.  
  227. int OpenDTConvert_DATATYPEWindow( void )
  228. {
  229.     struct NewGadget    ng;
  230.     struct Gadget    *g;
  231.     UWORD        lc, tc;
  232.     UWORD        wleft = DTConvert_DATATYPELeft, wtop = DTConvert_DATATYPETop, ww, wh;
  233.  
  234.     ComputeFont( DTConvert_DATATYPEWidth, DTConvert_DATATYPEHeight );
  235.  
  236.     ww = ComputeX( DTConvert_DATATYPEWidth );
  237.     wh = ComputeY( DTConvert_DATATYPEHeight );
  238.  
  239.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  240.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  241.  
  242.     if ( ! ( g = CreateContext( &DTConvert_DATATYPEGList )))
  243.         return( 1L );
  244.  
  245.     for( lc = 0, tc = 0; lc < DTConvert_DATATYPE_CNT; lc++ ) {
  246.  
  247.         CopyMem((char * )&DTConvert_DATATYPENGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  248.  
  249.         ng.ng_VisualInfo = VisualInfo;
  250.         ng.ng_TextAttr   = Font;
  251.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  252.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  253.         ng.ng_Width      = ComputeX( ng.ng_Width );
  254.         ng.ng_Height     = ComputeY( ng.ng_Height);
  255.  
  256.         DTConvert_DATATYPEGadgets[ lc ] = g = CreateGadgetA((ULONG)DTConvert_DATATYPEGTypes[ lc ], g, &ng, ( struct TagItem * )&DTConvert_DATATYPEGTags[ tc ] );
  257.  
  258.         while( DTConvert_DATATYPEGTags[ tc ] ) tc += 2;
  259.         tc++;
  260.  
  261.         if ( NOT g )
  262.             return( 2L );
  263.     }
  264.  
  265.     DTConvert_DATATYPEZoom[0] = DTConvert_DATATYPELeft;
  266.     DTConvert_DATATYPEZoom[1] = DTConvert_DATATYPETop;
  267.     if ( DTConvert_DATATYPEWdt )
  268.         DTConvert_DATATYPEZoom[2] = TextLength( &Scr->RastPort, (UBYTE *)DTConvert_DATATYPEWdt, (ULONG)strlen((char *)DTConvert_DATATYPEWdt )) + 80;
  269.     else
  270.         DTConvert_DATATYPEZoom[2]  = 80L;
  271.         DTConvert_DATATYPEZoom[3] = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  272.  
  273.     if ( ! ( DTConvert_DATATYPEWnd = OpenWindowTags( NULL,
  274.                 WA_Left,    wleft,
  275.                 WA_Top,        wtop,
  276.                 WA_Width,    ww + OffX + Scr->WBorRight,
  277.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  278.                 WA_IDCMP,    LISTVIEWIDCMP|BUTTONIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_VANILLAKEY|IDCMP_MENUHELP|IDCMP_REFRESHWINDOW,
  279.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_SIMPLE_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  280.                 WA_Gadgets,    DTConvert_DATATYPEGList,
  281.                 WA_Title,    DTConvert_DATATYPEWdt,
  282.                 WA_ScreenTitle,    "DTConvert",
  283.                 WA_PubScreen,    Scr,
  284.                 WA_Zoom,    DTConvert_DATATYPEZoom,
  285.                 WA_AutoAdjust,    TRUE,
  286.                 WA_PubScreenFallBack,    TRUE,
  287.                 TAG_DONE )))
  288.     return( 4L );
  289.  
  290.     GT_RefreshWindow( DTConvert_DATATYPEWnd, NULL );
  291.  
  292.     return( 0L );
  293. }
  294.  
  295. void CloseDTConvert_DATATYPEWindow( void )
  296. {
  297.     if ( DTConvert_DATATYPEWnd        ) {
  298.         CloseWindow( DTConvert_DATATYPEWnd );
  299.         DTConvert_DATATYPEWnd = NULL;
  300.     }
  301.  
  302.     if ( DTConvert_DATATYPEGList      ) {
  303.         FreeGadgets( DTConvert_DATATYPEGList );
  304.         DTConvert_DATATYPEGList = NULL;
  305.     }
  306. }
  307.  
  308.