home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / tools / pufferfish / source / gadgets.c < prev    next >
C/C++ Source or Header  |  1994-03-30  |  8KB  |  366 lines

  1. /*
  2.  * gadgets.c
  3.  *
  4.  * Create gadget routines
  5.  *
  6.  */
  7. #include <exec/types.h>
  8.  
  9. #include <intuition/intuition.h>
  10. #include <intuition/gadgetclass.h>
  11. #include <intuition/imageclass.h>
  12.  
  13. #include <clib/exec_protos.h>
  14. #include <clib/intuition_protos.h>
  15.  
  16. #include <stdio.h>
  17.  
  18. #include "buttonclass/headers.h"
  19. #include "buttonclass/buttonclass.h"
  20. #include "PufferFish.h"
  21.  
  22. extern struct Library *IntuitionBase;
  23. extern struct Library *GfxBase;
  24.  
  25. ULONG height1, height2, width1, width2;
  26. ULONG newleft, newtop;
  27.  
  28. struct Image *upimage, *downimage, *frameimage, *frame, *start, *end, *checkimage, *drive, *drivename[5], *drive_frame;
  29. struct Gadget *prop[2], *uparrows[8], *downarrows[8], *digits[8], *integer[2], *format, *drives[5];
  30.  
  31. extern int frame_height;
  32.  
  33. extern Class *BoxedStringClass, *buttonclass;
  34.  
  35. /*
  36.  * make_digits()
  37.  *
  38.  * Creates digit gadgets
  39.  *
  40.  * NOTE: Should probably just make a "groupgclass" object from these
  41.  *       (or a new BOOPSI class).
  42.  *
  43.  * Returns TRUE on success, FALSE otherwise
  44.  *
  45.  */
  46. BOOL make_digits( void )
  47. {
  48.     int i;
  49.     BOOL ret = FALSE;
  50.     
  51.     GetAttr( IA_Width, upimage, &width1 );
  52.     if( width1 < drawinfo->dri_Font->tf_XSize )
  53.     {
  54.         width1 = drawinfo->dri_Font->tf_XSize;
  55.     }
  56.     GetAttr( IA_Height, upimage, &height1 );
  57.     width2 = ( width1 - (drawinfo->dri_Font->tf_XSize + 4) ) / 2; /* extra 4 for frame */
  58.     height2 = drawinfo->dri_Font->tf_YSize;
  59.     
  60.     for( i = 0; i < 8; i += 1 )
  61.     {
  62.         newtop = win->BorderTop + GF_TOPBORDER * 2 - 2 + ((i >= 4) ? frame_height + drawinfo->dri_Font->tf_YSize : 0);
  63.         newleft = win->BorderLeft + ( GF_LEFTBORDER * 2 ) + ((i >= 4) ? i-4 : i) * width1;
  64.         uparrows[i] = (struct Gadget *)NewObject( NULL, "buttongclass",
  65.             GA_ID,    i + GAD_UPARROW_1,
  66.             GA_Top,    newtop,
  67.             GA_Left,newleft,
  68.             GA_Image,upimage,
  69.             GA_RelVerify,TRUE,
  70.             ((i > 0) ? GA_Previous : TAG_IGNORE ), ((i > 0) ? uparrows[i-1] : NULL),
  71.             GA_GadgetHelp, TRUE,
  72.             GA_Disabled, FALSE,
  73.             TAG_END );
  74.         if( uparrows[i] == NULL )
  75.         {
  76.             break;
  77.         }
  78.     }
  79.     if( i < 8 )
  80.     {
  81.         free_digits();
  82.     }
  83.     else
  84.     {
  85.         for( i = 0; i < 8; i += 1 )
  86.         {
  87.             newtop = win->BorderTop + GF_TOPBORDER * 2 + height1 + ((i >= 4) ? frame_height + drawinfo->dri_Font->tf_YSize : 0);
  88.             newleft = win->BorderLeft + ( GF_LEFTBORDER * 2 ) + ((i >= 4) ? i-4 : i) * width1 + width2 + 1;
  89.             digits[i] = (struct Gadget *)NewObject( NULL, "frbuttonclass",
  90.                 GA_ID,    i + GAD_DIGIT_1,
  91.                 GA_Top, newtop,
  92.                 GA_Left,newleft,
  93.                 GA_RelVerify, TRUE,
  94.                 GA_DrawInfo, drawinfo,
  95.                 GA_Image, frameimage,
  96.                 GA_Text, dig_text[i],
  97.                 GA_Previous, ((i > 0) ? digits[i-1] : uparrows[7]),
  98.                 GA_GadgetHelp, TRUE,
  99.                 TAG_END );
  100.             if( digits[i] == NULL )
  101.             {
  102.                 break;
  103.             }
  104.         }
  105.         if( i < 8 )
  106.         {
  107.             free_digits();
  108.         }
  109.         else
  110.         {
  111.             newtop += (drawinfo->dri_Font->tf_YSize + 2 + 4);
  112.             for( i = 0; i < 8; i += 1 )
  113.             {
  114.                 newtop = win->BorderTop + GF_TOPBORDER * 2 + height1 + ((i >= 4) ? frame_height + drawinfo->dri_Font->tf_YSize : 0) + drawinfo->dri_Font->tf_YSize + 2 + 4;
  115.                 newleft = win->BorderLeft + ( GF_LEFTBORDER * 2 ) + ((i >= 4) ? i-4 : i) * width1;
  116.                 downarrows[i] = (struct Gadget *)NewObject( NULL, "buttongclass",
  117.                     GA_ID,    i + GAD_DOWNARROW_1,
  118.                     GA_Top,    newtop,
  119.                     GA_Left,newleft,
  120.                     GA_Image,downimage,
  121.                     GA_RelVerify, TRUE,
  122.                     GA_Previous, ((i > 0) ? downarrows[i-1] : digits[7]),
  123.                     GA_Disabled, TRUE,
  124.                     GA_GadgetHelp, TRUE,
  125.                     TAG_END );
  126.                 if( downarrows[i] == NULL )
  127.                 {
  128.                     break;
  129.                 }
  130.             }
  131.             if( i < 8 )
  132.             {
  133.                 free_digits();
  134.             }
  135.             else
  136.             {
  137.                 for( i = 0; i < 2; i += 1 )
  138.                 {
  139.                     newtop = win->BorderTop + GF_TOPBORDER * 2 + height1 + i * (frame_height + drawinfo->dri_Font->tf_YSize);
  140.                     integer[i] = (struct Gadget *)NewObject( BoxedStringClass, NULL,
  141.                         GA_ID,    GAD_INTEGER_1 + i,
  142.                         GA_Top,    newtop,
  143.                         GA_Left, win->BorderLeft + (GF_LEFTBORDER * 2) + (width1 * 9 / 2),
  144.                         GA_Height, drawinfo->dri_Font->tf_YSize + 4,
  145.                         GA_Width, drawinfo->dri_Font->tf_XSize * 5 + 8,
  146.                         GA_RelVerify,TRUE,
  147.                         GA_Previous,((i==0) ? downarrows[7] : integer[0]),
  148.                         STRINGA_LongVal, firstdisk,
  149.                         STRINGA_MaxChars, 5,
  150.                         STRINGA_ExitHelp, TRUE,
  151.                         GA_TabCycle, TRUE,
  152.                         GA_GadgetHelp, TRUE,
  153.                         TAG_END );
  154.                     if( integer[i] == NULL )
  155.                     {
  156.                         break;
  157.                     }
  158.                 }
  159.                 if( i == 2 )
  160.                 {
  161.                     for( i = 0; i < 2; i += 1 )
  162.                     {
  163.                         newtop = win->BorderTop + GF_TOPBORDER * 2 + 2 * height1 + 2 + i * (frame_height + drawinfo->dri_Font->tf_YSize) + drawinfo->dri_Font->tf_YSize + 2 + 4;
  164.                         prop[i] = (struct Gadget *)NewObject( NULL, "propgclass",
  165.                             GA_ID,    GAD_PROP_1 + i,
  166.                             PGA_Freedom, FREEHORIZ,
  167.                             PGA_Top, 0,
  168.                             PGA_Total, lastdisk - firstdisk + 1,
  169.                             PGA_Visible, 1,
  170.                             PGA_NewLook, TRUE,
  171.                             GA_Top, newtop,
  172.                             GA_Left, win->BorderLeft + (GF_LEFTBORDER * 2),
  173.                             GA_Height, drawinfo->dri_Font->tf_YSize,
  174.                             GA_Width, width1 * 4,
  175.                             GA_Previous, ((i==0) ? integer[1] : prop[0]),
  176.                             GA_GadgetHelp, TRUE,
  177.                             GA_RelVerify, TRUE,
  178.                             TAG_END );
  179.                         if( prop[i] == NULL )
  180.                         {
  181.                             break;
  182.                         }
  183.                     }
  184.                     if( i == 2 )
  185.                     {
  186.                         ret = TRUE;
  187.                     }
  188.                     else
  189.                     {
  190.                         free_digits();
  191.                     }
  192.                 }
  193.                 else
  194.                 {
  195.                     free_digits();
  196.                 }
  197.             }
  198.         }
  199.     }
  200.     return( ret );
  201. }
  202.  
  203. /*
  204.  * free_digits()
  205.  *
  206.  * Frees digit gadgets created by make_digits()
  207.  *
  208.  */
  209. void free_digits( void )
  210. {
  211.     int i;
  212.     
  213.     for( i = 0; i < 2; i += 1 )
  214.     {
  215.         if( prop[i] )
  216.         {
  217.             DisposeObject( prop[i] );
  218.         }
  219.         if( integer[i] )
  220.         {
  221.             DisposeObject( integer[i] );
  222.         }
  223.     }
  224.     for( i = 0; i < 8; i += 1)
  225.     {
  226.         if( downarrows[i] )
  227.         {
  228.             DisposeObject( downarrows[i] );
  229.         }
  230.         if( digits[i] )
  231.         {
  232.             DisposeObject( digits[i] );
  233.         }
  234.         if( uparrows[i] )
  235.         {
  236.             DisposeObject( uparrows[i] );
  237.         }
  238.     }
  239. }
  240.  
  241. /*
  242.  * make_drives()
  243.  *
  244.  * Creates drive gadgets
  245.  *
  246.  * Returns TRUE on success, FALSE otherwise
  247.  *
  248.  */
  249. BOOL make_drives( void )
  250. {
  251.     int i;
  252.     ULONG width, height, checkheight;
  253.     BOOL ret = FALSE;
  254.     
  255.     GetAttr( IA_Height, checkimage, &checkheight );
  256.     height = checkheight;
  257.     if( height < drawinfo->dri_Font->tf_YSize )
  258.     {
  259.         height = drawinfo->dri_Font->tf_YSize;
  260.     }
  261.     GetAttr( IA_Width, upimage, &width );
  262.     
  263.     for( i = 0; i < 5; i += 1 )
  264.     {
  265.         newtop = win->BorderTop + GF_TOPBORDER * 2 - 2 + i * (height + 5);
  266.         drives[i] = (struct Gadget *)NewObject( buttonclass, NULL,
  267.             GA_ID,    GAD_DRIVE_0 + i,
  268.             GA_Top,    newtop,
  269.             GA_Left,win->BorderLeft + GF_LEFTBORDER * 2 + width * 6 + drawinfo->dri_Font->tf_XSize * 5 + 8
  270.                 + IntuiTextLength( &drivenames_text[0] ),
  271.             GA_Height, checkheight,
  272.             GA_Width, width + 8,
  273.             BUT_Image,checkimage,
  274.             GA_RelVerify,TRUE,
  275.             GA_Previous, ((i > 0) ? drives[i-1] : prop[1]),
  276.             GA_Disabled, ((avail_disks & 1<<i) ? FALSE : TRUE),
  277.             GA_GadgetHelp, TRUE,
  278.             GA_ToggleSelect, TRUE,
  279.             GA_Selected, FALSE,
  280.             TAG_END );
  281.         if( drives[i] == NULL )
  282.         {
  283.             break;
  284.         }
  285.     }
  286.     if( i < 5 )
  287.     {
  288.         free_drives();
  289.     }
  290.     else
  291.     {
  292.         ret = TRUE;
  293.     }
  294.     return( ret );
  295. }
  296.  
  297. /*
  298.  * free_drives()
  299.  *
  300.  * Frees drive gadgets created by make_drives()
  301.  *
  302.  */
  303. void free_drives( void )
  304. {
  305.     int i;
  306.     
  307.     for( i = 0; i < 5; i += 1 )
  308.     {
  309.         if( drives[i] )
  310.         {
  311.             DisposeObject( drives[i] );
  312.         }
  313.     }
  314. }
  315.  
  316. /*
  317.  * make_gadgets()
  318.  *
  319.  * Creates other (non-digit and non-drive) gadgets
  320.  *
  321.  * Returns TRUE on success, FALSE otherwise
  322.  *
  323.  */
  324. BOOL make_gadgets( void )
  325. {
  326.     BOOL ret = FALSE;
  327.     ULONG arrowwidth, checkwidth, checkheight;
  328.     ULONG left;
  329.     
  330.     GetAttr( IA_Width, upimage, &arrowwidth );
  331.     GetAttr( IA_Width, checkimage, &checkwidth );
  332.     GetAttr( IA_Height, checkimage, &checkheight );
  333.     
  334.     left = ( win->Width - (win->BorderLeft + GF_LEFTBORDER + arrowwidth * 6 + drawinfo->dri_Font->tf_XSize * 5 ) - TextLength( win->RPort, "Go", 2 ) - 8 - drawinfo->dri_Font->tf_XSize - 4 - GF_RIGHTBORDER - win->BorderRight ) / 2;
  335.     if( format = (struct Gadget *)NewObject( buttonclass, NULL,
  336.         GA_ID,        GAD_START,
  337.         BUT_Text,    "_Go",
  338.         GA_Top,        win->BorderTop + GF_TOPBORDER + 5 * (checkheight + 5) + GF_TOPBORDER * 2,
  339.         GA_Left,    win->BorderLeft + GF_LEFTBORDER + arrowwidth * 6 + drawinfo->dri_Font->tf_XSize * 5 + 8 + left,
  340.         GA_Height,    drawinfo->dri_Font->tf_YSize + 8,
  341.         GA_Width,    TextLength(win->RPort, "Go", 2) + 8 + drawinfo->dri_Font->tf_XSize,
  342.         GA_Previous,    drives[3],
  343.         GA_DrawInfo,    drawinfo,
  344.         GA_RelVerify,    TRUE,
  345.         GA_GadgetHelp,    TRUE,
  346.         TAG_END ))
  347.     {