home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / lib / c / sysreq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-04  |  2.8 KB  |  99 lines

  1. /* 
  2. ** Invoke a system requester using AutoRequest().
  3. ** Copyright (C) 1998 David Benn
  4. ** 
  5. ** This program is free software; you can redistribute it and/or
  6. ** modify it under the terms of the GNU General Public License
  7. ** as published by the Free Software Foundation; either version 2
  8. ** of the License, or (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program; if not, write to the Free Software
  17. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18. **  
  19. ** Author: David J Benn
  20. **   Date: 13th January, 
  21. **       22nd-27th December 1993,
  22. **       2nd January 1994,
  23. **       14th August 1994
  24. */
  25.  
  26. #include <exec/types.h>
  27. #include <intuition/intuition.h>
  28.  
  29. #define  FontWidth  (RPort->Font->tf_XSize)
  30. #define  FontHeight (RPort->Font->tf_YSize)
  31.  
  32. /* externals variables */
  33. extern struct Window *Wdw;
  34. extern struct RastPort *RPort;
  35.  
  36. /* external functions */
  37. extern ULONG stringlength();
  38.  
  39. /* functions */
  40. void fill_intuitext(txt,left,top,msg)
  41. struct IntuiText *txt;
  42. SHORT  left,top;
  43. UBYTE  *msg;
  44. {
  45.   txt->FrontPen  = 0;
  46.   txt->BackPen   = 1;
  47.   txt->DrawMode  = JAM1;
  48.   txt->LeftEdge  = left;
  49.   txt->TopEdge   = top;
  50.   txt->ITextFont = NULL;    /* use default font */
  51.   txt->IText     = msg;
  52.   txt->NextText  = NULL;
  53. }
  54.  
  55. SHORT sysrequest(response2,response1,body)
  56. char *response2,*response1,*body;
  57. {
  58. SHORT  req_x,req_y,x_offset,y_offset;
  59. struct IntuiText main;
  60. struct IntuiText pprompt;
  61. struct IntuiText nprompt;
  62.  
  63.   /* 
  64.   ** Build and display a system requester, then
  65.   ** return a result (0 or 1) indicating which
  66.   ** button was pressed. Note: response1 must
  67.   ** be non-NULL for this to work and the Intuition
  68.   ** library must be open. Under Wb 1.3, the width
  69.   ** of the requester is derived from the width of
  70.   ** the "body" text. Wb 2.04 controls this width
  71.   ** independently.
  72.   */
  73.  
  74.   if (response1 == NULL) return 0;    /* 0 = error */
  75.  
  76.   req_x = stringlength(body)*FontWidth + FontWidth*5;
  77.   req_y = FontHeight*8;
  78.  
  79.   x_offset = FontWidth >> 1;
  80.   y_offset = FontHeight >> 1;
  81.  
  82.   fill_intuitext(&main,FontWidth,FontHeight,body);
  83.  
  84.   if (response2 != NULL)
  85.   {
  86.     /* two gadgets (eg: OK + CANCEL) */
  87.     fill_intuitext(&pprompt,x_offset,y_offset,response1);
  88.     fill_intuitext(&nprompt,x_offset,y_offset,response2);
  89.     return -1*AutoRequest(Wdw,&main,&pprompt,&nprompt,NULL,NULL,req_x,req_y);
  90.   }
  91.   else
  92.   {
  93.     /* one gadget (eg: OK) */
  94.     fill_intuitext(&nprompt,x_offset,y_offset,response1);
  95.     AutoRequest(Wdw,&main,NULL,&nprompt,NULL,NULL,req_x,req_y);
  96.     return -1;
  97.   }
  98. }
  99.