home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / window / omega2 / omwin.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-25  |  17.1 KB  |  848 lines

  1. //
  2. // *************************************************************************
  3. // *                                                                       *
  4. // *    OMEGA C++ Windowing Class Library                                  *
  5. // *    =================================                                  *
  6. // *                                                                       *
  7. // *    Copyright 1991,92 Tom Clancy                                       *
  8. // *    Submitted to the public domain, April 1992                         *
  9. // *                                                                       *
  10. // *************************************************************************
  11. // *                                                                       *
  12. // *    Window Class Methods                                               *
  13. // *                                                                       *
  14. // *************************************************************************
  15. //
  16.  
  17. #include <dos.h>
  18. #include <string.h>
  19. #include <conio.h>
  20. #include "fastwrit.hpp"
  21. #include "omwin.hpp"
  22.  
  23. extern unsigned char boxstyles[2][6];
  24.  
  25. oWindow::oWindow(int x, int y, int w, int l, int fg, int bk, int style) {
  26.  
  27.   Startx=x;
  28.   Starty=y;
  29.   TxtStartx=Startx+1;
  30.   TxtStarty=Starty+1;
  31.   Just=mNojust;
  32.   Len=l;
  33.   Wid=w;
  34.   Endx=x+w-1;
  35.   Endy=y+l-1;
  36.   FGcolor=fg;
  37.   BKcolor=bk;
  38.   Shadowed=TRUE;
  39.   ShadDir=shBottomright;
  40.   Opened=FALSE;
  41.   if(style<0 || style>1)
  42.     style=0;
  43.   Wstyle=style;
  44.   strcpy(title,"\0");
  45.   tPos=tCenter;
  46.   Canresize=TRUE;
  47.   Canclose=TRUE;
  48.   Canexpand=TRUE;
  49.   Candrag=TRUE;
  50.   tFGcolor=WHITE;
  51.   tBKcolor=BLUE;
  52.   Buttoncolor=LIGHTGREEN;
  53.   Expanded=FALSE;
  54.   BoundX=1;
  55.   BoundY=1;
  56.   BoundX2=getscreenwid();
  57.   BoundY2=getscreenlen();
  58.   MinWid=20;
  59.   MinLen=3;
  60.   Oldx=Startx;
  61.   Oldy=Starty;
  62.   Oldx2=Endx;
  63.   Oldy2=Endy;
  64.   OldLen=Len;
  65.   OldWid=Wid;
  66.   SolidHeader=TRUE;
  67. }
  68.  
  69. oWindow::oWindow () {
  70.  
  71.   Startx=1;
  72.   Starty=1;
  73.   TxtStartx=Startx+1;
  74.   TxtStarty=Starty+1;
  75.   Just=mNojust;
  76.   Endx=1;
  77.   Endy=1;
  78.   Len=1;
  79.   Wid=1;
  80.   FGcolor=WHITE;
  81.   BKcolor=BLACK;
  82.   Shadowed=TRUE;
  83.   ShadDir=shBottomright;
  84.   Opened=FALSE;
  85.   Wstyle=SINGLEBAR;
  86.   strcpy(title,"\0");
  87.   tPos=tCenter;
  88.   Canresize=TRUE;
  89.   Canclose=TRUE;
  90.   Canexpand=TRUE;
  91.   Candrag=TRUE;
  92.   tFGcolor=WHITE;
  93.   tBKcolor=BLUE;
  94.   Buttoncolor=LIGHTGREEN;
  95.   Expanded=FALSE;
  96.   BoundX=1;
  97.   BoundY=1;
  98.   BoundX2=getscreenwid();
  99.   BoundY2=getscreenlen();
  100.   MinWid=20;
  101.   MinLen=3;
  102.   Oldx=Startx;
  103.   Oldy=Starty;
  104.   Oldx2=Endx;
  105.   Oldy2=Endy;
  106.   OldLen=Len;
  107.   OldWid=Wid;
  108.   SolidHeader=TRUE;
  109. }
  110.  
  111. oWindow::~oWindow() {
  112.   setlastcmd(0);
  113.   setlastevent(0);
  114.   if(Opened)
  115.    disposewin();
  116. }
  117.  
  118. void oWindow::setwindow(int x, int y, int w, int l, int fg, int bk, int style) {
  119.  
  120.   Startx=x;
  121.   Starty=y;
  122.   TxtStartx=Startx+1;
  123.   TxtStarty=Starty+1;
  124.   Len=l;
  125.   Wid=w;
  126.   Endx=x+w-1;
  127.   Endy=y+l-1;
  128.   FGcolor=fg;
  129.   BKcolor=bk;
  130.   Opened=FALSE;
  131.   if(style<0 || style>1)
  132.     style=0;
  133.   Wstyle=style;
  134. }
  135.  
  136. void oWindow::setjustify(windowjust j) {
  137.   Just=j;
  138.   if(Just!=mNojust) {
  139.     dragging(OFF);
  140.     resizing(OFF);
  141.     expanding(OFF);
  142.   }
  143. }
  144.  
  145.  
  146. void oWindow::display_info() {}
  147. void oWindow::display_help() {}
  148.  
  149. void oWindow::settitle(char *s, int tpos, int fgcolor, int bkcolor) {
  150.   char *t;
  151.   t=new char[strlen(s)+1];
  152.   strcpy(t,s);
  153.   if(strlen(t)>130)
  154.     t[129]='\0';
  155.   strcpy(title,t);
  156.   delete t;
  157.   tFGcolor=fgcolor;
  158.   tBKcolor=bkcolor;
  159.   tPos=tpos;
  160.   if(tPos<0 || tPos>2)
  161.     tPos=tCenter;
  162. }
  163.  
  164.  
  165. void oWindow::dragging(int d) {
  166.   Candrag=d;
  167.   if(Candrag && Just!=mNojust)
  168.     Candrag=FALSE;
  169. }
  170.  
  171. void oWindow::expanding(int e) {
  172.   Canexpand=e;
  173.   if(Canexpand && Just!=mNojust)
  174.     Canexpand=FALSE;
  175. }
  176.  
  177. void oWindow::resizing(int r) {
  178.   Canresize=r;
  179.   if(Canresize && Just!=mNojust)
  180.     Canresize=FALSE;
  181. }
  182.  
  183. void oWindow::snaptocenter() {
  184.   closewin();
  185.   int oj=Just;
  186.   Just=mCenterBoth;
  187.   openwin();
  188.   Just=oj;
  189. }
  190.  
  191. void oWindow::openwin() {
  192.  
  193.   int newx,newy;
  194.  
  195.   if(!Opened) {
  196.     if(Just!=mNojust) {
  197.       newx=(getscreenwid()/2)-((getright()-getleft()+1) /2);
  198.       newy=(getscreenlen()/2)-((getbottom()-gettop()+1) /2);
  199.       switch(Just) {
  200.  
  201.     case mCenterX :
  202.       setwindow(newx,gettop(),getwid(),getlen(),getfgcolor(),getbkcolor(),getstyle());
  203.       break;
  204.  
  205.     case mCenterY :
  206.       setwindow(getleft(),newy,getwid(),getlen(),getfgcolor(),getbkcolor(),getstyle());
  207.       break;
  208.  
  209.     case mCenterBoth :
  210.       setwindow(newx,newy,getwid(),getlen(),getfgcolor(),getbkcolor(),getstyle());
  211.       break;
  212.       }
  213.     }
  214.     Opened=TRUE;
  215.     Behind.i=save_image(Startx, Starty, Endx, Endy, Behind);
  216.     absdrawbox(Startx, Starty, Endx, Endy, FGcolor, BKcolor, Wstyle);
  217.     if(SolidHeader)
  218.       absfillarea(Startx+1,Starty,Endx-1, Starty, tFGcolor, tBKcolor, 32);
  219.     if(Canclose) {
  220.       if(SolidHeader) {
  221.     oScreen::writeat(Startx+2,Starty,FGcolor,tBKcolor,"[ ]");
  222.     oScreen::chwriteat(Startx+3,Starty,Buttoncolor,tBKcolor,CLOSECHAR);
  223.       }
  224.       else {
  225.     oScreen::writeat(Startx+2,Starty,FGcolor,BKcolor,"[ ]");
  226.     oScreen::chwriteat(Startx+3,Starty,Buttoncolor,BKcolor,CLOSECHAR);
  227.       }
  228.     }
  229.     if(Canexpand) {
  230.       if(SolidHeader) {
  231.     oScreen::writeat(Endx-4,Starty,FGcolor,tBKcolor,"[ ]");
  232.     if(!Expanded)
  233.       oScreen::chwriteat(Endx-3,Starty,Buttoncolor,tBKcolor,EXPANDCHAR);
  234.     else
  235.       oScreen::chwriteat(Endx-3,Starty,Buttoncolor,tBKcolor,CONTRACTCHAR);
  236.       }
  237.       else {
  238.     oScreen::writeat(Endx-4,Starty,FGcolor,BKcolor,"[ ]");
  239.     if(!Expanded)
  240.       oScreen::chwriteat(Endx-3,Starty,Buttoncolor,BKcolor,EXPANDCHAR);
  241.     else
  242.       oScreen::chwriteat(Endx-3,Starty,Buttoncolor,BKcolor,CONTRACTCHAR);
  243.       }
  244.     }
  245.     if(Canresize) {
  246.       oScreen::chwriteat(Endx-1,Endy,Buttoncolor,BKcolor,RESIZECHAR1);
  247.       oScreen::chwriteat(Endx,Endy,Buttoncolor,BKcolor,RESIZECHAR2);
  248.     }
  249.     showtitle();
  250.     if(Shadowed)
  251.       drawshadow();
  252.     display_info();
  253.   }
  254. }
  255.  
  256. void oWindow::showtitle() {
  257.   if(strlen(title)) {
  258.     char *t;
  259.     t=new char[strlen(title)+1];
  260.     strcpy(t,title);
  261.     if(strlen(t)>Wid-10)
  262.       t[Wid-10]='\0';
  263.  
  264.     switch(tPos) {
  265.  
  266.       case tLeft :
  267.     break;
  268.       case tRight :
  269.     break;
  270.       case tCenter :
  271.     abswritebetween(Starty,Startx,Endx,tFGcolor,tBKcolor,t);
  272.     break;
  273.     }
  274.     delete t;
  275.   }
  276. }
  277.  
  278.  
  279. void oWindow::closewin() {
  280.  
  281.   if(Opened) {
  282.     show_image(Startx, Starty, Behind);
  283.     hideshadow();
  284.     disposewin();
  285.     cursoroff();
  286.   }
  287. }
  288.  
  289. void oWindow::disposewin() {
  290.   if(Opened) {
  291.     Opened=FALSE;
  292.     delete Behind.i;
  293.     if(Shadowed) {
  294.       if(Side1)
  295.     delete Shside1.i;
  296.       if(Side2)
  297.     delete Shside2.i;
  298.     }
  299.   }
  300. }
  301.  
  302.  
  303.  
  304. void oWindow::drawshadow() {
  305.  
  306.   register int i;
  307.   int ex,ey;
  308.  
  309.   Side1=FALSE;
  310.   Side2=FALSE;
  311.  
  312.   if(Opened && Shadowed) {
  313.     switch(ShadDir) {
  314.       case shTopleft :
  315.     Shy1=Starty-1;
  316.     if(Shy1<BoundY)
  317.       Shy1=BoundY;
  318.     if(getscreenlen()==25)
  319.       Shx1=Startx-2;
  320.     else
  321.       Shx1=Startx-1;
  322.     if(Shx1<BoundX)
  323.       Shx1=BoundX;
  324.     ex=Endx-2;
  325.     if(Starty>BoundY) {
  326.       Side1=TRUE;
  327.       Shside1.i=save_image(Shx1,Shy1,ex,Shy1,Shside1);
  328.       for(i=Shx1; i<=ex; i++)
  329.         oScreen::writeshadow(i,Shy1);
  330.     }
  331.     Shy2=Starty;
  332.     Shx2=Shx1;
  333.     ey=Starty+Len-2;
  334.     if(Startx>BoundX) {
  335.       Side2=TRUE;
  336.       if(Startx>2 && getscreenlen()==25)
  337.         Shside2.i=save_image(Shx2,Shy2,Shx2+1,ey,Shside2);
  338.       else
  339.         Shside2.i=save_image(Shx2,Shy2,Shx2,ey,Shside2);
  340.       for(i=Shy2; i<=ey; i++) {
  341.         oScreen::writeshadow(Shx2,i);
  342.         if(Startx>2 && getscreenlen()==25)
  343.           oScreen::writeshadow(Shx2+1,i);
  344.       }
  345.     }
  346.     break;
  347.  
  348.       case shTopright :
  349.     Shy1=Starty-1;
  350.     if(Shy1<BoundY)
  351.       Shy1=BoundY;
  352.     Shx1=Startx+2;
  353.     if(getscreenlen()==25)
  354.       ex=Endx+2;
  355.     else
  356.       ex=Endx+1;
  357.     if(ex>BoundX2)
  358.       ex=BoundX2;
  359.     if(Starty>BoundY) {
  360.       Side1=TRUE;
  361.       Shside1.i=save_image(Shx1,Shy1,ex,Shy1,Shside1);
  362.       for(i=Shx1; i<=ex; i++)
  363.         oScreen::writeshadow(i,Shy1);
  364.     }
  365.     if(Endx<BoundX2) {
  366.       Shx2=Endx+1;
  367.       Side2=TRUE;
  368.       ex=Endx+2;
  369.       if(ex>BoundX2)
  370.         ex=BoundX2;
  371.       Shy2=Starty;
  372.       ey=Endy-1;
  373.       if(getscreenlen()==25)
  374.         Shside2.i=save_image(Shx2,Shy2,ex,ey,Shside2);
  375.       else
  376.         Shside2.i=save_image(Shx2,Shy2,Shx2,ey,Shside2);
  377.       for(i=Shy2; i<=ey; i++) {
  378.         oScreen::writeshadow(Shx2,i);
  379.         if(ex==Endx+2 && getscreenlen()==25)
  380.           oScreen::writeshadow(ex,i);
  381.       }
  382.     }
  383.     break;
  384.  
  385.       case shBottomleft :
  386.     if(Endy<BoundY2) {
  387.       Shy1=Endy+1;
  388.       ex=Endx-2;
  389.       if(Startx>BoundX) {
  390.         if(getscreenlen()==25)
  391.           Shx1=Startx-2;
  392.         else
  393.           Shx1=Startx-1;
  394.         if(Shx1<BoundX)
  395.           Shx1=BoundX;
  396.       }
  397.       else
  398.         Shx1=Startx;
  399.       Side1=TRUE;
  400.       Shside1.i=save_image(Shx1,Shy1,ex,Shy1,Shside1);
  401.       for(i=Shx1; i<=ex; i++)
  402.         oScreen::writeshadow(i,Shy1);
  403.     }
  404.     if(Startx>BoundX) {
  405.       if(getscreenlen()==25)
  406.         Shx2=Startx-2;
  407.       else
  408.         Shx2=Startx-1;
  409.       if(Shx2<BoundX)
  410.         Shx2=BoundX;
  411.       ex=Startx-1;
  412.       Shy2=Starty+1;
  413.       ey=Endy;
  414.       Side2=TRUE;
  415.       Shside2.i=save_image(Shx2,Shy2,ex,ey,Shside2);
  416.       for(i=Shy2; i<=ey; i++) {
  417.         oScreen::writeshadow(Shx2,i);
  418.         if(Shx2==Startx-2 && getscreenlen()==25)
  419.           oScreen::writeshadow(ex,i);
  420.       }
  421.     }
  422.  
  423.     break;
  424.  
  425.       case shBottomright :
  426.     if(Endy<BoundY2) {
  427.       Shy1=Endy+1;
  428.       Shx1=Startx+2;
  429.       ex=Endx;
  430.       if(Endx<BoundX2) {
  431.         if(getscreenlen()==25)
  432.           ex=Endx+2;
  433.         else
  434.           ex=Endx+1;
  435.         if(ex>BoundX2)
  436.           ex=Endx+1;
  437.       }
  438.       Side1=TRUE;
  439.       Shside1.i=save_image(Shx1,Shy1,ex,Shy1,Shside1);
  440.       for(i=Shx1; i<=ex; i++)
  441.         oScreen::writeshadow(i,Shy1);
  442.     }
  443.     if(Endx<BoundX2) {
  444.       Shx2=Endx+1;
  445.       ex=Endx+2;
  446.       if(ex>BoundX2)
  447.         ex=Shx2;
  448.       Shy2=Starty+1;
  449.       ey=Endy;
  450.       Side2=TRUE;
  451.       if(getscreenlen()==25)
  452.         Shside2.i=save_image(Shx2,Shy2,ex,ey,Shside2);
  453.       else
  454.         Shside2.i=save_image(Shx2,Shy2,Shx2,ey,Shside2);
  455.       for(i=Shy2; i<=ey; i++) {
  456.         oScreen::writeshadow(Shx2,i);
  457.         if(ex==Endx+2 && getscreenlen()==25)
  458.           oScreen::writeshadow(ex,i);
  459.       }
  460.     }
  461.     break;
  462.     }
  463.   }
  464. }
  465.  
  466. void oWindow::hideshadow() {
  467.   if(Opened && Shadowed) {
  468.     if(Side1)
  469.       show_image(Shx1,Shy1,Shside1);
  470.     if(Side2)
  471.       show_image(Shx2,Shy2,Shside2);
  472.   }
  473.  
  474. }
  475.  
  476.  
  477. int oWindow::onclose() {
  478.   return (((buttonx() >= getleft()+2) &&
  479.        (buttonx() <= getleft()+4) &&
  480.        (buttony() == gettop())));
  481. }
  482.  
  483. int oWindow::onexpand() {
  484.   return (((buttonx() >= getright()-4) &&
  485.        (buttonx() <= getright()-2) &&
  486.        (buttony() == gettop())));
  487. }
  488.  
  489. int oWindow::ondrag() {
  490.   return ((buttonx() >= getleft()) &&
  491.       (buttonx() <= getright()) &&
  492.       (buttony() == gettop()));
  493.  
  494. }
  495.  
  496. int oWindow::onresize() {
  497.   return (buttonx() >= getright()-1 &&
  498.       buttonx() <= getright() &&
  499.       buttony() == getbottom());
  500.  
  501. }
  502.  
  503. void oWindow::expandwin() {
  504.   cursoroff();
  505.   if(!Expanded && Opened && Just==mNojust) {
  506.     Expanded=ON;
  507.     Oldx=Startx;
  508.     Oldy=Starty;
  509.     Oldx2=Endx;
  510.     Oldy2=Endy;
  511.     OldLen=Len;
  512.     OldWid=Wid;
  513.     activate_virtual();
  514.     closewin();
  515.     setwindow(BoundX,BoundY,BoundX2-BoundX+1,BoundY2-BoundY+1,FGcolor,BKcolor,Wstyle);
  516.     openwin();
  517.     deactivate_virtual();
  518.   }
  519. }
  520.  
  521. void oWindow::contractwin() {
  522.   cursoroff();
  523.   if(Expanded && Opened && Just==mNojust) {
  524.     Expanded=OFF;
  525.     activate_virtual();
  526.     closewin();
  527.     setwindow(Oldx,Oldy,OldWid,OldLen,FGcolor,BKcolor,Wstyle);
  528.     openwin();
  529.     deactivate_virtual();
  530.   }
  531.  
  532. }
  533.  
  534. void oWindow::mSizewin() {
  535.  
  536.   int mx,my,mb;
  537.   int ox,oy;
  538.   int Shad,Dir;
  539.  
  540.   if(Canresize && Just==mNojust) {
  541.     activate_virtual();
  542.     Shad=Shadowed;
  543.     Dir=ShadDir;
  544.     closewin();
  545.     setshadow(OFF,shNoshadow);
  546.     openwin();
  547.     mouse::getmouse(mx,my,mb);
  548.     ox=mx;
  549.     oy=my;
  550.     hidemouse();
  551.     while(mb==1) {
  552.       cursoroff();
  553.       display_virtual();
  554.       closewin();
  555.       while(ox==mx && oy==my && mb==1)
  556.     mouse::getmouse(mx,my,mb);
  557.       if(mx<getleft()+MinWid-1) {
  558.     mx=getleft()+MinWid-1;
  559.     setmouse(mx,my);
  560.       }
  561.       if(my<gettop()+MinLen-1) {
  562.     my=gettop()+MinLen-1;
  563.     setmouse(mx,my);
  564.       }
  565.       if(mx>BoundX2) {
  566.     mx=BoundX2;
  567.     setmouse(mx,my);
  568.       }
  569.       if(my>BoundY2) {
  570.     my=BoundY2;
  571.     setmouse(mx,my);
  572.       }
  573.       setwindow(Startx, Starty, mx-Startx+1, my-Starty+1, FGcolor, BKcolor, Wstyle);
  574.       openwin();
  575.       ox=mx;
  576.       oy=my;
  577.     }
  578.     closewin();
  579.     if(getleft()==BoundX && getright()==BoundX2 && gettop()==BoundY &&
  580.        getbottom()==BoundY2)
  581.       Expanded=ON;
  582.     else
  583.       Expanded=OFF;
  584.     setshadow(Shad,Dir);
  585.     openwin();
  586.     deactivate_virtual();
  587.  
  588.   }
  589. }
  590.  
  591.  
  592. void oWindow::mDragwin() {
  593.  
  594.   int mx,my,mb;
  595.   int ox,oy;
  596.   int sx,l,w;
  597.   image gag,b;
  598.  
  599.   cursoroff();
  600.  
  601.   if(!Expanded && Candrag && Just==mNojust) {
  602.  
  603.     gag.i=save_image(getleft(),gettop(),getright(),getbottom(),gag);
  604.     activate_virtual();
  605.     closewin();
  606.     b.i=save_image(getleft(),gettop(),getright(),getbottom(),b);
  607.     l=b.len;
  608.     w=b.wid;
  609.     mouse::getmouse(mx,my,mb);
  610.     sx=mx-getleft();
  611.     setmouse(getleft(),gettop());
  612.     mouse::getmouse(mx,my,mb);
  613.     ox=mx;
  614.     oy=my;
  615.     hidemouse();
  616.     while(mb==1) {
  617.       show_image(mx,my,gag);
  618.       display_virtual();
  619.       while(ox==mx && oy==my && mb==1)
  620.     mouse::getmouse(mx,my,mb);
  621.       show_image(ox,oy,b);
  622.       if(mx+w>BoundX2) {
  623.     mx=BoundX2-w+1;
  624.     setmouse(mx,my);
  625.       }
  626.       if(my+l>BoundY2) {
  627.     my=BoundY2-l+1;
  628.     setmouse(mx,my);
  629.       }
  630.       if(mx<BoundX) {
  631.     mx=BoundX;
  632.     setmouse(mx,my);
  633.       }
  634.       if(my<BoundY) {
  635.     my=BoundY;
  636.     setmouse(mx,my);
  637.       }
  638.  
  639.       delete b.i;
  640.       save_image(mx,my,mx+w-1,my+l-1,b);
  641.       ox=mx;
  642.       oy=my;
  643.     }
  644.     delete gag.i;
  645.     delete b.i;
  646.     setwindow(mx,my,w,l,FGcolor,BKcolor,Wstyle);
  647.     openwin();
  648.  
  649.     deactivate_virtual();
  650.  
  651.     setmouse(getleft()+sx,my);
  652.   }
  653.  
  654. }
  655.  
  656. int oWindow::handle_key_event() {
  657.  
  658.   switch(getkeycode()) {
  659.     case F1 :
  660.       display_help();
  661.       return cmdHelp;
  662.       break;
  663.  
  664.     case AltF3:
  665.       if(Canclose) {
  666.     closewin();
  667.     return cmdClose;
  668.       }
  669.       break;
  670.  
  671.     case F5 :
  672.       if(Canexpand) {
  673.     if(Expanded) {
  674.       contractwin();
  675.       return cmdContract;
  676.     }
  677.     expandwin();
  678.     return cmdExpand;
  679.       }
  680.       break;
  681.  
  682.     case CtrlF5 :
  683.       //kbDragwin();
  684.       return cmdDrag;
  685.       break;
  686.   }
  687.   return 0;
  688. }
  689.  
  690. int oWindow::withinwindow() {
  691.  
  692.   if(buttonx()>Startx && buttonx() < Endx &&
  693.      buttony()>Starty && buttony() < Endy) {
  694.  
  695.     setbuttonx(buttonx()-Startx);
  696.     setbuttony(buttony()-Starty);
  697.     return 1;
  698.  
  699.   }
  700.   return 0;
  701.  
  702. }
  703.  
  704. int oWindow::handle_mouse_event() {
  705.  
  706.   if(buttonb()==1) {
  707.     if(withinwindow())
  708.       return cmdWithinwin;
  709.     else
  710.     if(onclose() && Canclose) {
  711.       closewin();
  712.       while(event());
  713.       return cmdClose;
  714.     }
  715.     else
  716.     if(onexpand() && Canexpand) {
  717.       if(Expanded) {
  718.     contractwin();
  719.     while(event());
  720.     return cmdContract;
  721.       }
  722.       else {
  723.     expandwin();
  724.     while(event());
  725.     return cmdExpand;
  726.       }
  727.     }
  728.     else
  729.     if(onresize()) {
  730.       mSizewin();
  731.       return cmdResize;
  732.     }
  733.     else
  734.     if(ondrag()) {
  735.       mDragwin();
  736.       return cmdDrag;
  737.     }
  738.  
  739.  
  740.   }
  741.   return cmdNocmd;
  742. }
  743.  
  744. void oWindow::run() {
  745.  
  746.   while(getlastcmd()!=cmdClose)
  747.     handle_events();
  748. }
  749.  
  750.  
  751.  
  752. void oWindow::getmouse(int &x, int &y, int &b) {
  753.   int tx,ty,tb;
  754.   mouse::getmouse(tx,ty,tb);
  755.   if(tx>Startx && tx<Endx &&
  756.      ty>Starty && ty<Endy) {
  757.     x=tx-Startx;
  758.     y=ty-Starty;
  759.     b=tb;
  760.   }
  761.   else {
  762.     x=tx;
  763.     y=ty;
  764.     b=tb;
  765.   }
  766.  
  767. }
  768.  
  769.  
  770. //
  771. // window write routines
  772. //
  773.  
  774. char *oWindow::makewinstr(int x, int y, char *s, char *t) {
  775.  
  776.  
  777.   t=new char[strlen(s)+1];
  778.   t[0]='\0';
  779.   if(x<Wid-1 && y<Len-1) {
  780.     strcpy(t,s);
  781.     if(x+strlen(t)>Wid-1)
  782.       t[Wid-x-1]='\0';
  783.   }
  784.   return t;
  785. }
  786.  
  787. void oWindow::writeat(int x, int y, int fg, int bk, char *str) {
  788.  
  789.   hidemouse();
  790.   if(x<1) x=1;
  791.   if(y<1) y=1;
  792.   char *t;
  793.   t=makewinstr(x,y,str,t);
  794.   if(strlen(t))
  795.     fastwritestr(TxtStartx+x-1,TxtStarty+y-1,(char)fg,(char)bk,t,getvvseg(),getvvofs());
  796.   delete t;
  797. }
  798.  
  799. void oWindow::plainwriteat(int x, int y, char *str) {
  800.  
  801.   hidemouse();
  802.   if(x<1) x=1;
  803.   if(y<1) y=1;
  804.   char *t;
  805.   t=makewinstr(x,y,str,t);
  806.   if(strlen(t))
  807.     plainwritestr(TxtStartx+x-1,TxtStarty+y-1,t,getvvseg(),getvvofs());
  808.   delete t;
  809. }
  810.  
  811. void oWindow::chwriteat(int x, int y, int fg, int bk, unsigned char c) {
  812.  
  813.   hidemouse();
  814.   if(x<Wid-1 && y<Len-1)
  815.     fastwritech(TxtStartx+x-1,TxtStarty+y-1,(char)fg,(char)bk,c,getvvseg(),getvvofs());
  816. }
  817.  
  818. void oWindow::plainchwriteat(int x, int y, unsigned char c) {
  819.  
  820.   hidemouse();
  821.   if(x<Wid-1 && y<Len-1)
  822.     plainwritech(TxtStartx+x-1,TxtStarty+y-1,c,getvvseg(),getvvofs());
  823. }
  824.  
  825. void oWindow::writeshadow(int x, int y) {
  826.   hidemouse();
  827.   if(x<Wid-1 && y<Len-1)
  828.     shadowchar(TxtStartx+x-1,TxtStarty+y-1,getvvseg(),getvvofs());
  829. }
  830.  
  831. void oWindow::movexy(int x, int y) {
  832.   hidemouse();
  833.   if(x<Wid-1 && y<Len-1)
  834.     oScreen::movexy(TxtStartx+x-1,TxtStarty+y-1);
  835.   else
  836.     cursoroff();
  837. }
  838.  
  839. void oWindow::attribln(int y, int x1, int x2, int fg, int bk) {
  840.   hidemouse();
  841.   if(y<Len-1) {
  842.     if(x1>Wid-2) x1=Wid-2;
  843.     if(x2>Wid-2) x2=Wid-2;
  844.     fastattrib(TxtStarty+y-1, TxtStartx+x1-1, TxtStartx+x2-1, (char)fg, (char)bk,getvvseg(),getvvofs());
  845.   }
  846. }
  847.  
  848.