home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.1 / JimmDemos / DemoSource / buildreq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.7 KB  |  131 lines

  1. /* buildreq.c -- build autorequester
  2.  * (thanks to Neil Katin for an earlier version)
  3.  * Copyright (c) 1988, I and I Computing and Commodore-Amiga, Inc.
  4.  *
  5.  * Executables based on this information may be used in software
  6.  * for Commodore Amiga computers.  All other rights reserved.
  7.  *
  8.  * This information is provided "as is"; no warranties are made.
  9.  * All use is at your own risk, and no liability or responsibility is assumed.
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <intuition/intuition.h>
  15.  
  16. #define MAX(a,b)  (( (a) > (b) )? (a): (b))
  17. #define MIN(a,b)  (( (a) < (b) )? (a): (b))
  18.  
  19. #define TEXTO    (12)
  20.  
  21. /* returns 0 if failure to get needed memory, else
  22.  * returns value from AutoRequest
  23.  */
  24. buildAutoRequest( window, textArray, pText, nText, pflags, nflags)
  25. struct Window    *window;        /* we require this parameter    */
  26. UBYTE        **textArray;
  27. UBYTE        *pText;
  28. UBYTE        *nText;
  29. ULONG        pflags;
  30. ULONG        nflags;
  31. {
  32.     int        height;        /* dimensions for requester    */
  33.     int        width;
  34.     int        wheight;    /* dimensions for window    */
  35.     int        wwidth;
  36.     int        sizeArray;    /* bytes in all IntuiText structs    */
  37.     int        result;
  38.     UBYTE    **sa;
  39.     struct IntuiText    *itArray, *ita, *itPos,*itNeg;
  40.     struct RastPort    *rp;
  41.     struct Screen    *screen;
  42.     int        fontheight;
  43.  
  44.     if ( (! *textArray) || (! window) ) return (0);
  45.  
  46.     screen = window->WScreen;
  47.     rp = &screen->RastPort;
  48.     fontheight = rp->TxHeight;
  49.  
  50.     printf("bAR: fontheight: %d\n", fontheight);
  51.  
  52.     /*** compute width and height (of Requester, for now) ***/
  53.  
  54.     /* width for gadgets and some spacing    */
  55.     width = TextLength( rp, pText, (ULONG) strlen( pText ))
  56.         + TextLength( rp, nText, (ULONG) strlen( nText )) + 70;
  57.  
  58.     /* account for gadgets, and miscellaneous spacing    */
  59.     height = fontheight + 20;
  60.  
  61.     for ( sa = textArray; *sa; sa++ )
  62.     {
  63.         height += fontheight + 2;
  64.         width = MAX( width, TextLength( rp, *sa, (ULONG) strlen( *sa )));
  65.     }
  66.  
  67.     /*** initialize IntuiText structures    ***/
  68.  
  69.     /* count 2 IntuiText structures for pText and nText    */
  70.     sizeArray = ((sa - textArray) + 2) * sizeof( struct IntuiText );
  71.  
  72.     itArray = (struct IntuiText *) AllocMem( (LONG) sizeArray, (LONG)MEMF_CLEAR);
  73.  
  74.     if ( ! itArray ) return ( 0 );
  75.  
  76.     itArray->TopEdge = 4;    /* spacing from top of Requester    */
  77.     for ( ita = itArray, sa = textArray; *sa; sa++, ita++ )
  78.     {
  79.         initIntuiText( ita, *sa, &ita[ 1 ], fontheight );
  80.     }
  81.     /* now ita points to first of two text structures for retry/cancel    */
  82.     ita[ -1 ].NextText = NULL;        /* terminate list    */
  83.  
  84.     itPos = ita++;
  85.     initIntuiText( itPos, pText, NULL, fontheight );
  86.  
  87.     itNeg = ita;
  88.     initIntuiText( itNeg, nText, NULL, fontheight );
  89.  
  90.     itPos->TopEdge = itNeg->TopEdge = AUTOTOPEDGE;
  91.     itPos->LeftEdge = itNeg->LeftEdge = AUTOLEFTEDGE;
  92.  
  93.     /*** do it ***/
  94.  
  95.     /* account for unknown width of sizing gadget :-( */
  96.     wwidth = MIN( width+screen->WBorLeft+screen->WBorRight+(2*TEXTO)+20,
  97.         screen->Width);
  98.     wheight = MIN( height + screen->BarHeight +
  99.     screen->WBorTop + screen->WBorBottom, screen->Height);
  100.  
  101.     printf("width, height %d/%d\n", width, height);
  102.     printf("window w/h: %d/%d\n", wwidth, wheight);
  103.  
  104.     result = (int) AutoRequest( window, itArray, itPos, itNeg,
  105.         pflags, nflags, (LONG) wwidth, (LONG) wheight);
  106.  
  107.     FreeMem( itArray, (LONG) sizeArray );
  108.  
  109.     return ( result );
  110. }
  111.  
  112.  
  113. /* assumes structures are cleared (0) already */
  114. initIntuiText( it, text, itNext, fontheight )
  115. struct IntuiText *it;
  116. UBYTE *text;
  117. struct IntuiText *itNext;
  118. int    fontheight;
  119. {
  120.     it->FrontPen = 0;
  121.     it->BackPen = 1;
  122.     it->DrawMode = JAM1;
  123.     it->IText = text;
  124.     it->LeftEdge = TEXTO;
  125.  
  126.     if( itNext ) {
  127.         it->NextText = itNext;
  128.         itNext->TopEdge = it->TopEdge + fontheight +2;
  129.     }
  130. }
  131.