home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / program / gempp15b.zoo / src / gemal.cc < prev    next >
C/C++ Source or Header  |  1993-04-25  |  2KB  |  69 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is Copyright 1992,1993 by Warwick W. Allison.
  4. //  This file is part of the gem++ library.
  5. //  You are free to copy and modify these sources, provided you acknowledge
  6. //  the origin by retaining this notice, and adhere to the conditions
  7. //  described in the file COPYING.LIB.
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11. #include "gemal.h"
  12. #include "gemr.h"
  13. #include <aesbind.h>
  14. #include <string.h>
  15. #include <stdarg.h>
  16. #include <stdio.h>
  17.  
  18. GEMalert::GEMalert(const GEMrsc& in, int RSCindex)
  19. {
  20.     text=in.String(RSCindex);
  21. }
  22.  
  23. GEMalert::GEMalert(const char* lines, const char* buttons)
  24. {
  25.     // I REALLY don't like non-RSCfile GEM stuff...
  26.     text=new char[256];
  27.     strcat(text,"[1]["); // HA!  I wont even let you use other icons.
  28.     strcat(text,lines);
  29.     strcat(text,"][");
  30.     strcat(text,buttons);
  31.     strcat(text,"]");
  32. }
  33.  
  34. int GEMalert::Alert(int defbutt=-1)
  35. {
  36.     // Number of buttons, n = 1 + (number of '|' after final '[').
  37.     for (int i=0; text[i]; i++);
  38.     for (int n=1; text[i]!='['; i--) if (text[i]=='|') n++;
  39.  
  40.     if (defbutt<0) {
  41.         // -toomany becomes leftmost
  42.         if (-defbutt>n) defbutt=1;
  43.         else defbutt=n+1+defbutt;
  44.     } else {
  45.         // +toomany becomes rightmost
  46.         if (defbutt>n) defbutt=n;
  47.     }
  48.  
  49.     return form_alert(defbutt,text);
  50. }
  51.  
  52. int GEMalert::Alertf(int defbutt, ...)
  53. {
  54.     va_list ap;
  55.  
  56.     va_start(ap, defbutt);
  57.     char buf[256];
  58.     vsprintf(buf, text, ap);
  59.  
  60.     // Temporarily swap "buf" for "text" member, and use normal Alert() method
  61.     char* tmp=text;
  62.     text=buf;
  63.     int result=Alert(defbutt);
  64.     text=tmp;
  65.     va_end(ap);
  66.  
  67.     return result;
  68. }
  69.