home *** CD-ROM | disk | FTP | other *** search
- #include "xw.h"
-
- /*-----
- */
-
- #include "xk.h"
- #include "xo.h"
- #include "xx.h"
-
- #include <string.h>
-
- /*-----
- XWinMgr::pop
- affiche un menu pop-up
- */
-
- class PopWin : public XWin
- {
- private :
- int OUT;
-
- protected :
- virtual void on_call (XObj *obj);
- virtual void on_char (int key);
- virtual void on_lmou (int, int);
-
- public :
- PopWin (int wdt, int hgh, const char *hdr, XOpt *opt, int out);
- };
-
- PopWin::PopWin (int wdt, int hgh, const char *hdr, XOpt *opt, int out)
-
- : XWin(wdt + 2, hgh + 2)
-
- {
- int cnt;
- char * str;
- XOpt * ptr;
-
- type(xw_VMENU);
-
- if (hdr == 0)
- defw(xw_STDWIN & ~xw_HEADER);
- else
- head(hdr);
-
- for (cnt = 0, ptr = opt; cnt < hgh; cnt++, ptr++)
- {
-
- if ((str = ptr->str) != 0)
- link(new XOption(ptr->idt, cnt, 0, wdt, str, ptr->key));
- else
- link(new XBreak(0, cnt, 0, wdt));
-
- }
-
- OUT = out;
- }
-
- void PopWin::on_call (XObj *obj)
- {
- retn(obj->id());
- hide();
- }
-
- void PopWin::on_char (int key)
- {
-
- if (key == xk_ESC)
- {
- retn(0);
- hide();
- }
-
- }
-
- void PopWin::on_lmou (int, int)
- {
-
- if (OUT != 0)
- {
- retn(0);
- hide();
- }
-
- }
-
- int XWinMgr::pop (const char *hdr, XOpt *opt, int out)
- {
- int wdt, tmp, cnt;
- char * str;
- XOpt * ptr;
- PopWin * win;
-
- wdt = 20;
- ptr = opt;
- cnt = 0;
-
- while (ptr->idt != -1)
- {
-
- if ((str = ptr->str) != 0)
- {
-
- if ((tmp = strlen(str) - _scnt(str, '&') + 2) > wdt)
- wdt = tmp;
-
- }
-
- ++cnt;
- ++ptr;
- }
-
- win = new PopWin(wdt, cnt, hdr, opt, out);
- tmp = xw.exec(win);
- delete win;
-
- return (tmp);
- }
-
-