home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 18 / CD_ASCQ_18_111294_W.iso / dos / prg / c / x_lib10 / xw_ok.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-20  |  1.3 KB  |  83 lines

  1. #include    "xw.h"
  2.  
  3. /*-----
  4. */
  5.  
  6. #include    "xk.h"
  7. #include    "xo.h"
  8. #include    "xx.h"
  9.  
  10. /*-----
  11.     XWinMgr::ok
  12.     affiche une boite de dialogue standard : Ok
  13. */
  14.  
  15. class    OkWin : public XWin
  16.         {
  17.     protected :
  18.         virtual    void    on_call (XObj *obj);
  19.         virtual    void    on_char (int key);
  20.  
  21.     public :
  22.         OkWin (int wdt, int hgh, const char *hdr, const char *msg);
  23.         };
  24.  
  25. OkWin::OkWin (int wdt, int hgh, const char *hdr, const char *msg)
  26.  
  27.         : XWin(wdt + 8, hgh + 8)
  28.  
  29.         {
  30.         XText *    obj;
  31.  
  32.         if (hdr == 0)
  33.             defw(xw_STDWIN & ~xw_HEADER);
  34.         else
  35.             head(hdr);
  36.  
  37.         link(new XBox(1, 1, 1, wdt + 4, hgh + 2, 0, 1));
  38.         obj = (XText *)link(new XText(2, 2, 3, wdt, hgh, 0, 0));
  39.         link(new XPush(3, hgh + 4, (wdt - 2) >> 1, 8, "&Ok", xk_aO));
  40.  
  41.         obj->defs(0, msg);
  42.         }
  43.  
  44. void    OkWin::on_call (XObj *obj)
  45.         {
  46.  
  47.         if (obj->type() == xo_PUSH)
  48.             {
  49.             xo(obj, XPush)->push(1);
  50.             hide();
  51.             }
  52.  
  53.         }
  54.  
  55. void    OkWin::on_char (int key)
  56.         {
  57.  
  58.         if ((key == xk_ESC) || (key == xk_RET))
  59.             hide();
  60.  
  61.         }
  62.  
  63. void    XWinMgr::ok (const char *hdr, const char *msg)
  64.         {
  65.         int        wdt, hgh;
  66.         OkWin *    win;
  67.  
  68.         if ((wdt = _smax(msg, '\n') + 2) > 70)
  69.             wdt = 70;
  70.         else if (wdt < 26)
  71.             wdt = 26;
  72.  
  73.         if ((hgh = _scnt(msg, '\n') + 2) > 20)
  74.             hgh = 20;
  75.         else if (hgh < 3)
  76.             hgh = 3;
  77.  
  78.         win = new OkWin(wdt, hgh, hdr, msg);
  79.         xw.exec(win);
  80.         delete win;
  81.         }
  82.  
  83.