home *** CD-ROM | disk | FTP | other *** search
/ Kyūkyoku!! X68000 Emulator / X68000Book.dat / mac / OLS / X68000 / Ko-Window / kow142s.lzh / wsrv / window.c < prev    next >
C/C++ Source or Header  |  1995-09-08  |  24KB  |  1,061 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include    <sys_doslib.h>
  4.  
  5. #define    _K_WINDOW
  6.  
  7. #include "clip.h"
  8. #include "window.h"
  9. #include "vram.h"
  10. #include "manager.h"
  11.  
  12. #define    WINDOW_OPEN_ID        1234
  13. #define    NOREDRAW            (WindowAttrTra|WindowAttrInvisible)
  14.  
  15. int        (*SendEventExec)();
  16. int        (*WindowError)();
  17.  
  18. static    WindowClass    *RootWindowPtr ;
  19.  
  20. /*
  21.     proto -s window.c > temp
  22. */
  23. static    void    _WindowPop( WindowClass*, WindowClass*, ClipClass* );
  24. static    void    _WindowScroll( WindowClass*, ClipClass*, WindowClass*, int, int );
  25. static    void    __WindowScroll( WindowClass*, ClipClass*, int, int );
  26. static    void    WindowDrawOffset( WindowClass*, DrawBuf*, int, int, int, int );
  27. static    void    _WindowDraw( DrawBuf*, int, ClipClass*, WindowClass*, int, int );
  28. static    void    SendEventRedraw( WindowClass* );
  29. static    void    SendEventRedrawClip( WindowClass*, ClipClass* );
  30. static    void    WindowRedrawAll( WindowClass*, WindowClass*, ClipClass*, int );
  31. static    void    WindowDeleteList( WindowClass* );
  32. static    void    WindowAppendList( WindowClass* );
  33. static    void    WindowClipSet( ClipClass*, WindowClass*, ClipClass* );
  34. static    int        SetUpClip( ClipClass*, ClipClass*, ClipClass* );
  35. static    int        SetDownClip( ClipClass*, ClipClass*, ClipClass* );
  36. static    int        SetLeftClip( ClipClass*, ClipClass*, ClipClass* );
  37. static    int        SetRightClip( ClipClass*, ClipClass*, ClipClass* );
  38.  
  39.  
  40. void    WindowSet( wp, x, y, h, v, parent, id, event )
  41. WindowClass    *wp ;
  42. int            x, y, h, v ;
  43. WindowClass    *parent    ;
  44. int            id ;
  45. int            (*event)();
  46. {
  47.     ClipSet( (ClipClass*)wp, x, y, h, v );
  48.     wp->window.type = WindowType ;
  49.     wp->window.check = WINDOW_OPEN_ID ;
  50.     wp->window.client = 0 ;
  51.     wp->window.clientp = NULL ;
  52.     wp->window.ownerid = -1 ;
  53.     wp->window.attr = WindowAttrTra ;
  54.     wp->window.eventattr = EventAttrDefault ;
  55.     ClipSet( &(wp->window.curclip), 0, 0, h, v );
  56.     wp->window.hx = wp->window.hy = 0 ;
  57.     wp->window.parent = parent ;
  58.     wp->window.childtop = NULL ;
  59.     wp->window.childbottom = NULL ;
  60.     wp->window.id = id ;
  61.     wp->window.event = event ;
  62.     if ( parent == NULL )
  63.     {
  64.         VramClipPtr = (ClipClass*)wp ;
  65.         RootWindowPtr = wp ;
  66.     }
  67.     else
  68.         WindowAppendList( wp );
  69. }
  70.  
  71. /*  âEâCâôâhâEé╠âNâìü[âY  */
  72. void    WindowClose( wp )
  73. WindowClass    *wp ;
  74. {
  75.     WindowClass    *parent ;
  76. /*    DrawBuf        buf[1] ;    */    /* 19950804 Copel */
  77.  
  78.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowClose"  );
  79. /*
  80.     if ( wp->window.attr & WindowAttrGraphicUse )
  81.     {
  82.         DrawSetGraphicClear( buf, 0 );
  83.         WindowDraw( wp, buf, 1 );
  84.     }
  85. */
  86.     while( wp->window.childtop != NULL )
  87.         WindowClose( wp->window.childtop );
  88.     if ( wp->window.parent != NULL )
  89.     {
  90.         WindowDeleteList( wp );
  91.         if ( ( wp->window.attr & NOREDRAW ) == 0 )
  92.         {
  93.             parent = wp->window.parent ;
  94.             WindowRedrawAll( parent, wp->window.next, (ClipClass*)wp, TRUE );
  95.         }
  96.         if ( wp->window.ownerid != -1 )
  97.             WindowMemoryFree( wp );
  98.     }
  99.     wp->window.check = 0 ;
  100. }
  101.  
  102. /*  âNâëâCâAâôâgâfü[â^é╠É▌ÆΦ  */
  103. void    WindowSetClientData( wp, n, p )
  104. WindowClass    *wp ;
  105. int        n ;
  106. void    *p ;
  107. {
  108.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowSetClientData"  );
  109.     wp->window.client = n ;
  110.     wp->window.clientp = p ;
  111. }
  112.  
  113. /*    âEâCâôâhâEé╠æ«É½É▌ÆΦ  */
  114. void    WindowSetAttr( wp, attr )
  115. WindowClass    *wp ;
  116. int            attr ;
  117. {
  118.     int        old ;
  119. /*    DrawBuf    buf[1] ;    */    /* 19950804 Copel */
  120.  
  121.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowSetAttr"  );
  122.     old = wp->window.attr ;
  123.     wp->window.attr = attr ;
  124.  
  125.     if ( ! ( old & WindowAttrTra ) )
  126.     {
  127.         if ( ! ( old & WindowAttrInvisible  ) && ( attr & WindowAttrInvisible ) )
  128.         {
  129. /*
  130.             if ( wp->window.attr & WindowAttrGraphicUse )
  131.             {
  132.                 DrawSetGraphicClear( buf, 0 );
  133.                 WindowDraw( wp, buf, 1 );
  134.             }
  135. */
  136.             WindowRedrawAll( wp->window.parent, wp->window.next, (ClipClass*)wp, TRUE );
  137.         }
  138.         else if ( ( old & WindowAttrInvisible ) && ! ( attr & WindowAttrInvisible ) )
  139.         {
  140.             SendEventRedraw( wp );
  141.         }
  142.     }
  143. }
  144.  
  145. /*  âEâCâôâhâEé╠âCâxâôâgæ«É½  */
  146. void    WindowSetEventAttr( wp, attr )
  147. WindowClass    *wp ;
  148. int            attr ;
  149. {
  150.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowSetEventAttr"  );
  151.     wp->window.eventattr = attr ;
  152. }
  153.  
  154. /*    âEâCâôâhâEé╠â|âbâv  */
  155. void    WindowPop( wp )
  156. WindowClass    *wp ;
  157. {
  158.     WindowClass    *last ;
  159.  
  160.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowPop" );
  161.     if ( wp->window.last != NULL )
  162.     {
  163.         last = wp->window.last ;
  164.         WindowDeleteList( wp );
  165.         WindowAppendList( wp );
  166.         if ( ( wp->window.attr & NOREDRAW ) == 0 ){
  167.             ClipClass    oldwin= {wp->clip};        /* 1993 COR. */
  168. /*            _WindowPop( wp, last, (ClipClass*)&(wp->clip) );*/
  169.             _WindowPop( wp, last, &oldwin );
  170.         }
  171.     }
  172. }
  173.  
  174. static    void    _WindowPop( wp, last, oldwin )
  175. WindowClass    *wp, *last ;
  176. ClipClass    *oldwin ;
  177. {
  178.     int            x, y, h, v, vx, vy, ph, pv, n ;
  179.     WindowClass    *parent ;
  180.     ClipClass    clip, localclip, *savecp ;
  181.  
  182.     x = wp->clip.x1 ;
  183.     y = wp->clip.y1 ;
  184.     parent = wp->window.parent ;
  185.     if ( ( wp->window.attr & WindowAttrGraphicUse ) == 0 &&
  186.          ClipOverlap( &clip, oldwin, &(parent->window.curclip) ) )
  187.     {
  188.         if( (int)wp != (int)oldwin ){    /* 1993 COR.*/
  189.             if( x != oldwin->clip.x1 || y != oldwin->clip.y1 ){
  190.                 ClipClass    vramclip;
  191.                 WindowClipSet( &vramclip, parent, &clip );
  192.                 VramMove( x + vramclip.clip.x1 - oldwin->clip.x1,
  193.                           y + vramclip.clip.y1 - oldwin->clip.y1, &vramclip );
  194.             }
  195.         }
  196.         savecp = VramClipPtr ;
  197.         VramClipPtr = &clip ;
  198.         ClipGetSize( &(parent->window.curclip), &ph, &pv );
  199.         ClipGetSize( (ClipClass*)wp, &h, &v );
  200.         if ( oldwin->clip.y1 < 0 )
  201.         {
  202.             ClipSet( &clip, x, y, h, - oldwin->clip.y1 );
  203.             ClipSet( &localclip, 0, 0, h, - oldwin->clip.y1 );
  204.             SendEventRedrawClip( wp, &localclip );
  205.             y += - oldwin->clip.y1 ;
  206.             oldwin->clip.y1 = 0 ;
  207.         }
  208.         if ( oldwin->clip.y2 >= pv )
  209.         {
  210.             n = oldwin->clip.y2 - pv + 1 ;
  211.             ClipSet( &clip, x, y + v - n, h, n );
  212.             ClipSet( &localclip, 0, v - n, h, n );
  213.             SendEventRedrawClip( wp, &localclip );
  214.             oldwin->clip.y2 = pv - 1 ;
  215.         }
  216.         if ( oldwin->clip.x1 < 0 )
  217.         {
  218.             ClipSet( &clip, x, y, - oldwin->clip.x1 , v );
  219.             ClipSet( &localclip, 0, 0, - oldwin->clip.x1, v );
  220.             SendEventRedrawClip( wp, &localclip );
  221.             x += - oldwin->clip.x1 ;
  222.             oldwin->clip.x1 = 0 ;
  223.         }
  224.         if ( oldwin->clip.x2 >= ph )
  225.         {
  226.             n = oldwin->clip.x2 - ph + 1 ;
  227.             ClipSet( &clip, x + h - n, y, n, v );
  228.             ClipSet( &localclip, h - n, 0, n,  v );
  229.             SendEventRedrawClip( wp, &localclip );
  230.             oldwin->clip.y2 = ph - 1 ;
  231.         }
  232.         if ( last != NULL )
  233.         {
  234.             vx = x - oldwin->clip.x1 ;
  235.             vy = y - oldwin->clip.y1 ;
  236.             while( last != wp )
  237.             {
  238.                 if ( ClipOverlap( &clip, (ClipClass*)oldwin, (ClipClass*)&(last->clip) ) )
  239.                 {
  240.                     clip.clip.x1 += vx ;
  241.                     clip.clip.y1 += vy ;
  242.                     clip.clip.x2 += vx ;
  243.                     clip.clip.y2 += vy ;
  244.                     localclip = clip ;
  245.                     ClipMove( &localclip, clip.clip.x1 - wp->clip.x1,
  246.                                           clip.clip.y1 - wp->clip.y1 );
  247.                     SendEventRedrawClip( wp, &localclip );
  248.                 }
  249.                 last = last->window.last ;
  250.             }
  251.         }
  252.         VramClipPtr = savecp ;
  253.     }
  254.     else
  255.         SendEventRedraw( wp );
  256. }
  257.  
  258. /*  âEâCâôâhâEé╠âvâbâVâà  */
  259. void    WindowPush( wp )
  260. WindowClass    *wp ;
  261. {
  262.     WindowClass    *parent, *last, *next ;
  263.  
  264.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowPush" );
  265.  
  266.     if ( wp->window.next != NULL )
  267.     {
  268.         parent = wp->window.parent ;
  269.         next = wp->window.next ;
  270.         WindowDeleteList( wp );
  271.  
  272.         /*  ò`é½Æ╝é╡  */
  273.         if ( ( wp->window.attr & NOREDRAW ) == 0 )
  274.             WindowRedrawAll( parent, next, (ClipClass*)wp, FALSE );
  275.  
  276.         /*  âEâCâôâhâEâèâXâgé╔ÿAîï  */
  277.         wp->window.last = parent->window.childbottom ;
  278.         if ( wp->window.last != NULL )
  279.         {
  280.             last = wp->window.last ;
  281.             last->window.next = wp ;
  282.         }
  283.         wp->window.next = NULL ;
  284.         parent->window.childbottom = wp ;
  285.         if ( parent->window.childtop == NULL )
  286.             parent->window.childtop = wp ;
  287.     }
  288. }
  289.  
  290. /*    âEâCâôâhâEé╠ò`é½Æ╝é╡  */
  291. void    WindowRedraw( wp )
  292. WindowClass    *wp ;
  293. {
  294.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowRedraw" );
  295.     if ( ! ( wp->window.attr & WindowAttrInvisible ) )
  296.         SendEventRedraw( wp );
  297. }
  298.  
  299. /*    âEâCâôâhâEé╠ê┌ô«  */
  300. void    WindowMove( wp, x, y )
  301. WindowClass    *wp ;
  302. int        x, y ;
  303. {
  304.     WindowClass    *next, *last ;
  305.     ClipClass    oldwin ;
  306. /*    DrawBuf        buf[1] ;    */    /* 19950804 Copel */
  307.  
  308.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowMove" );
  309. /*
  310.     if ( wp->window.attr & WindowAttrGraphicUse )
  311.     {
  312.         DrawSetGraphicClear( buf, 0 );
  313.         WindowDraw( wp, buf, 1 );
  314.     }
  315. */
  316.     next = wp->window.next ;
  317.     last = wp->window.last ;
  318.     oldwin.clip = wp->clip ;
  319.  
  320.     ClipMove( (ClipClass*)wp, x, y );
  321.  
  322.     if ( last != NULL )
  323.     {
  324.         WindowDeleteList( wp );
  325.         WindowAppendList( wp );
  326.     }
  327.     if ( ( wp->window.attr & NOREDRAW ) == 0 )
  328.     {
  329.         _WindowPop( wp, last, &oldwin );
  330.         WindowRedrawAll( wp->window.parent, next, &oldwin, TRUE );
  331.     }
  332. }
  333.  
  334. /*    âEâCâôâhâEé╠ò╧î`  */
  335. void    WindowResize( wp, x, y, h, v )
  336. WindowClass    *wp ;
  337. int        x, y, h, v ;
  338. {
  339.     ClipClass    clip ;
  340. /*    DrawBuf        buf[1] ;    */    /* 19950804 Copel */
  341.  
  342.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowResize" );
  343. /*
  344.     if ( wp->window.attr & WindowAttrGraphicUse )
  345.     {
  346.         DrawSetGraphicClear( buf, 0 );
  347.         WindowDraw( wp, buf, 1 );
  348.     }
  349. */
  350.     clip.clip = wp->clip ;
  351.     ClipSet( (ClipClass*)wp, x, y, h, v );
  352.     ClipSet( &(wp->window.curclip), 0, 0, h, v );
  353.     if ( ( wp->window.attr & NOREDRAW ) == 0 )
  354.     {
  355.         SendEventRedraw( wp );
  356.         WindowRedrawAll( wp->window.parent, wp->window.next, &clip, TRUE );
  357.     }
  358. }
  359.  
  360. /*    âzü[âÇê╩Æué╠É▌ÆΦ  */
  361. void    WindowSetHome( wp, hx, hy )
  362. WindowClass    *wp ;
  363. int            hx, hy ;
  364. {
  365.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowSetHome" );
  366.     wp->window.hx = hx ;
  367.     wp->window.hy = hy ;
  368. }
  369.  
  370. /*  âEâCâôâhâEé╠âXâNâìü[âï  */
  371. void    WindowScroll( wp, dx, dy )
  372. WindowClass    *wp ;
  373. int            dx, dy ;
  374. {
  375.     ClipClass    clip ;
  376.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowScroll" );
  377.  
  378.     wp->window.hx += dx ;
  379.     wp->window.hy += dy ;
  380.  
  381.     if ( ( dx & 15 ) != 0 || ( wp->window.attr & WindowAttrGraphicUse ) )    /* ADDITION 19950804 Copel */
  382.     {
  383. /*        SendEventRedraw( wp );    */
  384.         SendEventRedrawClip( wp , &( wp->window.curclip ) ) ;    /* MODIFICATION 19950804 Copel */
  385.         return ;
  386.     }
  387.  
  388.     if ( wp->window.childbottom == NULL )
  389.     {
  390.         int        x, y;
  391.         clip = wp->window.curclip ;
  392.         x = wp->clip.x1 ;
  393.         y = wp->clip.y1 ;
  394.         clip.clip.x1 += x ;
  395.         clip.clip.y1 += y ;
  396.         clip.clip.x2 += x ;
  397.         clip.clip.y2 += y ;
  398.  
  399.         _WindowScroll( wp, &clip, wp, dx, dy );
  400.     }
  401.     else
  402.     {
  403.         int        h, v ;
  404.         WindowClass    window ;
  405.         WindowGetViewSize( wp, &h, &v );
  406.         ClipSet( &clip, 0, 0, h, v );
  407.         window.window.last = wp->window.childbottom ;
  408.         _WindowScroll( wp, &clip, &window, dx, dy );
  409.     }
  410. }
  411.  
  412. static    void    _WindowScroll( wp, cp, overwp, dx, dy )
  413. WindowClass    *wp, *overwp ;
  414. ClipClass    *cp ;
  415. int            dx, dy ;
  416. {
  417.     ClipClass    clip ;
  418.  
  419.     while( overwp->window.last != NULL )
  420.     {
  421.         overwp = overwp->window.last ;
  422.         if ( ( overwp->window.attr & NOREDRAW ) == 0 )
  423.         {
  424.             if ( ClipOverlap( &clip, cp, (ClipClass*)overwp ) )
  425.             {
  426.                 if ( SetUpClip( &clip, cp, (ClipClass*)overwp ) )
  427.                     _WindowScroll( wp, &clip, overwp, dx, dy );
  428.                 if ( SetLeftClip( &clip, cp, (ClipClass*)overwp ) )
  429.                     _WindowScroll( wp, &clip, overwp, dx, dy );
  430.                 if ( SetRightClip( &clip, cp, (ClipClass*)overwp ) )
  431.                     _WindowScroll( wp, &clip, overwp, dx, dy );
  432.                 if ( SetDownClip( &clip, cp, (ClipClass*)overwp ) )
  433.                     _WindowScroll( wp, &clip, overwp, dx, dy );
  434.                 return ;
  435.             }
  436.         }
  437.     }
  438.     overwp = overwp->window.parent ;
  439.  
  440.     if ( overwp == NULL )
  441.     {
  442.         __WindowScroll( wp, cp, dx, dy );
  443.     }
  444.     else
  445.     {
  446.         int        h, v;
  447.         WindowGetViewSize( overwp, &h, &v );
  448.         ClipSet( &clip, 0, 0, h, v );
  449.         if ( ClipOverlap( &clip, &clip, cp ) )
  450.         {
  451.             int        x, y;
  452.             x = overwp->clip.x1 + overwp->window.curclip.clip.x1 ;
  453.             y = overwp->clip.y1 + overwp->window.curclip.clip.y1 ;
  454.             clip.clip.x1 += x ;
  455.             clip.clip.y1 += y ;
  456.             clip.clip.x2 += x ;
  457.             clip.clip.y2 += y ;
  458.             _WindowScroll( wp, &clip, overwp, dx, dy );
  459.         }
  460.     }
  461. }
  462.  
  463. static    void    __WindowScroll( wp, cp, dx, dy )
  464. WindowClass    *wp ;
  465. ClipClass    *cp ;
  466. int            dx, dy ;
  467. {
  468.     int            h, v ;
  469.     ClipClass    clip, localclip, *saveclip ;
  470.  
  471.     WindowClipSet( &clip, (wp->window.parent), (ClipClass*)&(wp->clip) );
  472.  
  473.     ClipGetSize( cp, &h, &v );
  474.     ClipSet( &localclip, cp->clip.x1 - clip.clip.x1, cp->clip.y1 - clip.clip.y1, h, v );
  475.  
  476.     saveclip = VramClipPtr ;
  477.     clip = *cp ;
  478.     VramClipPtr = & clip ;
  479.  
  480.     if ( - h < dx && dx < h && - v < dy && dy < v )
  481.     {
  482.         VramScroll( cp, dx, dy );
  483.  
  484.         if ( dx > 0 )
  485.         {
  486.             VramClipPtr->clip.x1 = VramClipPtr->clip.x2 - dx + 1 ;
  487.             localclip.clip.x1 = localclip.clip.x2 - dx + 1 ;
  488.         }
  489.         else if ( dx < 0 )
  490.         {
  491.             VramClipPtr->clip.x2 = VramClipPtr->clip.x1 - dx - 1 ;
  492.             localclip.clip.x2 = localclip.clip.x1 - dx - 1 ;
  493.         }
  494.         else if ( dy > 0 )
  495.         {
  496.             VramClipPtr->clip.y1 = VramClipPtr->clip.y2 - dy + 1 ;
  497.             localclip.clip.y1 = localclip.clip.y2 - dy + 1 ;
  498.         }
  499.         else if ( dy < 0 )
  500.         {
  501.             VramClipPtr->clip.y2 = VramClipPtr->clip.y1 - dy - 1 ;
  502.             localclip.clip.y2 = localclip.clip.y1 - dy - 1 ;
  503.         }
  504.     }
  505.     SendEventRedrawClip( wp, &localclip );
  506.     VramClipPtr = saveclip ;
  507. }
  508.  
  509.  
  510. /*
  511.  *        âEâCâôâhâEé╓é╠ò`ëµ
  512.  */
  513.  
  514. void    WindowDrawAbs( wp, buf, n )
  515. WindowClass    *wp ;
  516. DrawBuf        *buf ;
  517. int            n ;
  518. {
  519.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowDrawAbs" );
  520.  
  521.     WindowDrawOffset( wp, buf, n, 0, 0, TRUE );
  522. }
  523.  
  524. void    WindowDraw( wp, buf, n )
  525. WindowClass    *wp ;
  526. DrawBuf        *buf ;
  527. int            n ;
  528. {
  529.     ErrorCheck( wp->window.check == WINDOW_OPEN_ID, "WindowDraw" );
  530.  
  531.     WindowDrawOffset( wp, buf, n, - wp->window.hx, - wp->window.hy, FALSE );
  532. }
  533.  
  534. static    void    WindowDrawOffset( wp, buf, n, ox, oy, flag )
  535. WindowClass    *wp ;
  536. DrawBuf        *buf ;
  537. int            n ;
  538. int            ox, oy ;
  539. int            flag ;
  540. {
  541.     WindowClass    window ;
  542.     ClipClass    clip ;
  543.     int            x, y, h, v ;
  544.  
  545.     if ( wp->window.attr & WindowAttrInvisible )
  546.         return ;
  547.  
  548.     if ( wp->window.childbottom == NULL || flag )
  549.     {
  550.         if ( flag )
  551.         {
  552.             clip = *(ClipClass*)wp ;
  553.             ox += wp->clip.x1 ;
  554.             oy += wp->clip.y1 ;
  555.         }
  556.         else
  557.         {
  558.             clip = wp->window.curclip ;
  559.             x = wp->clip.x1 ;
  560.             y = wp->clip.y1 ;
  561.             ox += x + wp->window.curclip.clip.x1 ;
  562.             oy += y + wp->window.curclip.clip.y1 ;
  563.             clip.clip.x1 += x ;
  564.             clip.clip.y1 += y ;
  565.             clip.clip.x2 += x ;
  566.             clip.clip.y2 += y ;
  567.         }
  568.     }
  569.     else
  570.     {
  571.         WindowGetViewSize( wp, &h, &v );
  572.         ClipSet( &clip, 0, 0, h, v );
  573.         window.window.last = wp->window.childbottom ;
  574.         window.window.parent = wp ;
  575.         wp = &window ;
  576.     }
  577.     if ( wp->window.parent == RootWindowPtr )
  578.     {
  579.         if ( ClipOverlap( &clip, &clip, VramClipPtr ) == FALSE )
  580.             return ;
  581.     }
  582.     _WindowDraw( buf, n, &clip, wp, ox, oy );
  583. }
  584.  
  585. static    void    _WindowDraw( buf, n, cp, overwp, ox, oy )
  586. DrawBuf        *buf ;
  587. int            n ;
  588. ClipClass    *cp ;
  589. WindowClass    *overwp ;
  590. int            ox, oy ;
  591. {
  592.     ClipClass    clip ;
  593.  
  594.     while( overwp->window.last != NULL )
  595.     {
  596.         overwp = overwp->window.last ;
  597.         if ( ( overwp->window.attr & NOREDRAW ) == 0 )
  598.         {
  599.             if ( ClipOverlap( &clip, cp, (ClipClass*)overwp ) )
  600.             {
  601.                 if ( SetUpClip( &clip, cp, (ClipClass*)overwp ) )
  602.                     _WindowDraw( buf, n, &clip, overwp, ox, oy );
  603.                 if ( SetLeftClip( &clip, cp, (ClipClass*)overwp ) )
  604.                     _WindowDraw( buf, n, &clip, overwp, ox, oy );
  605.                 if ( SetRightClip( &clip, cp, (ClipClass*)overwp ) )
  606.                     _WindowDraw( buf, n, &clip, overwp, ox, oy );
  607.                 if ( SetDownClip( &clip, cp, (ClipClass*)overwp ) )
  608.                     _WindowDraw( buf, n, &clip, overwp, ox, oy );
  609.                 return ;
  610.             }
  611.         }
  612.     }
  613.     overwp = overwp->window.parent ;
  614.  
  615.     if ( overwp == NULL )
  616.     {
  617.         VramDraw( buf, n, cp, ox, oy );
  618.     }
  619.     else
  620.     {
  621.         int            x, y, h, v ;
  622.         WindowGetViewSize( overwp, &h, &v );
  623.         ClipSet( &clip, 0, 0, h, v );
  624.         if ( ClipOverlap( &clip, &clip, cp ) )
  625.         {
  626.             x = overwp->clip.x1 + overwp->window.curclip.clip.x1 ;
  627.             y = overwp->clip.y1 + overwp->window.curclip.clip.y1 ;
  628.             clip.clip.x1 += x ;
  629.             clip.clip.y1 += y ;
  630.             clip.clip.x2 += x ;
  631.             clip.clip.y2 += y ;
  632.             _WindowDraw( buf, n, &clip, overwp, ox+x, oy+y );
  633.         }
  634.     }
  635. }
  636.  
  637. /*
  638.  *        âEâCâôâhâEÅεò±é╠èmò█
  639.  */
  640. int        WindowGetEventAttr( wp )
  641. WindowClass    *wp ;
  642. {
  643.     return( wp->window.eventattr );
  644. }
  645.  
  646. /* append 1994 9/8 H.Ogasawra (COR.) */
  647. int        WindowGetAttr( wp )
  648. WindowClass    *wp ;
  649. {
  650.     return( wp->window.attr );
  651. }
  652.  
  653. int        WindowGetClientData( wp )
  654. WindowClass    *wp ;
  655. {
  656.     return( wp->window.client );
  657. }
  658.  
  659. void    *WindowGetClientPointer( wp )
  660. WindowClass    *wp ;
  661. {
  662.     return( wp->window.clientp );
  663. }
  664.  
  665. void    WindowGetPosition( wp, xp, yp )
  666. WindowClass    *wp ;
  667. int            *xp, *yp ;
  668. {
  669.     *xp = wp->clip.x1 ;
  670.     *yp = wp->clip.y1 ;
  671. }
  672.  
  673. void    WindowGetViewPosition( wp, xp, yp )
  674. WindowClass    *wp ;
  675. int            *xp, *yp ;
  676. {
  677.     *xp = wp->window.curclip.clip.x1 ;
  678.     *yp = wp->window.curclip.clip.y1 ;
  679. }
  680.  
  681. void    WindowGetScreenPosition( wp, xp, yp )
  682. WindowClass    *wp ;
  683. int            *xp, *yp ;
  684. {
  685.     *xp = 0 ;
  686.     *yp = 0 ;
  687.     while( wp->window.parent != NULL )
  688.     {
  689.         *xp += wp->window.curclip.clip.x1 + wp->clip.x1 ;
  690.         *yp += wp->window.curclip.clip.y1 + wp->clip.y1 ;
  691.         wp = wp->window.parent ;
  692.     }
  693. }
  694.  
  695. void    WindowGetViewSize( wp, hp, vp )
  696. WindowClass    *wp ;
  697. int            *hp, *vp ;
  698. {
  699.     ClipGetSize( &(wp->window.curclip), hp, vp );
  700. }
  701.  
  702. void    WindowGetHome( wp, xp, yp )
  703. WindowClass    *wp ;
  704. int            *xp, *yp ;
  705. {
  706.     *xp = wp->window.hx ;
  707.     *yp = wp->window.hy ;
  708. }
  709.  
  710. WindowClass    *WindowGetParent( wp )
  711. WindowClass    *wp ;
  712. {
  713.     return( wp->window.parent );
  714. }
  715.  
  716. WindowClass    *WindowGetNext( wp )
  717. WindowClass    *wp ;
  718. {
  719.     do
  720.     {
  721.         wp = wp->window.next ;
  722.     }
  723.     while( wp != NULL && wp->window.attr & WindowAttrInvisible );
  724.     return( wp );
  725. }
  726.  
  727. WindowClass    *WindowGetLast( wp )
  728. WindowClass    *wp ;
  729. {
  730.     do
  731.     {
  732.         wp = wp->window.last ;
  733.     }
  734.     while( wp != NULL && wp->window.attr & WindowAttrInvisible );
  735.     return( wp );
  736. }
  737.  
  738. WindowClass    *WindowGetChildTop( wp )
  739. WindowClass    *wp ;
  740. {
  741.     wp = wp->window.childtop ;
  742.     while( wp != NULL && wp->window.attr & WindowAttrInvisible )
  743.         wp = wp->window.next ;
  744.     return( wp );
  745. }
  746.  
  747. WindowClass    *WindowGetChildBottom( wp )
  748. WindowClass    *wp ;
  749. {
  750.     wp = wp->window.childbottom ;
  751.     while( wp != NULL && wp->window.attr & WindowAttrInvisible )
  752.         wp = wp->window.last ;
  753.     return( wp );
  754. }
  755.  
  756. WindowClass    *WindowGetChild( wp, info )
  757. WindowClass    *wp ;
  758. EventInfo    *info ;
  759. {
  760.     int        x, y ;
  761.  
  762.     wp = wp->window.childtop ;
  763.     x = info->x ;
  764.     y = info->y ;
  765.     while( wp != NULL )
  766.     {
  767.         if ( ! ( wp->window.attr & WindowAttrInvisible ) && ClipInner( (ClipClass*)wp, x, y ) )
  768.         {
  769.             info->x = x - wp->clip.x1 ;
  770.             info->y = y - wp->clip.y1 ;
  771.             return( wp );
  772.         }
  773.         wp = wp->window.next ;
  774.     }
  775.     return( NULL );
  776. }
  777.  
  778.  
  779. /*
  780.  *        âCâxâôâgÅεò±
  781.  */
  782. int        SendEvent( id, event, wp, info )
  783. int            id ;
  784. int            (*event)();
  785. WindowClass    *wp ;
  786. EventInfo    *info ;
  787. {
  788.     if ( wp == NULL || wp->window.eventattr & ( 1 << info->option ) )
  789.     {
  790.         if ( id == -1 )
  791.         {
  792.             return( (*event)( wp, info ) );
  793.         }
  794.         else
  795.         {
  796.             return( (*SendEventExec)( id, event, wp, info ) );
  797.         }
  798.     }
  799.     return( FALSE );
  800. }
  801.  
  802. int        WindowSendEvent( wp, info )
  803. WindowClass    *wp ;
  804. EventInfo    *info ;
  805. {
  806.     if ( wp == NULL )
  807.         return( FALSE );
  808.     else
  809.         return( SendEvent( wp->window.id, wp->window.event, wp, info ) );
  810. }
  811.  
  812. int        WindowSendEventAll( id, info )
  813. int            id ;
  814. EventInfo    *info ;
  815. {
  816.     int            ret ;
  817.     WindowClass    *wp ;
  818.     void        **wpp ;
  819.  
  820.     ret = TRUE ;
  821.     wpp = &( RootWindowPtr->window.childtop );
  822.     while( *wpp != NULL )
  823.     {
  824.         wp = *wpp ;
  825.         if ( wp->window.ownerid == id )
  826.             ret = ret && WindowSendEvent( wp, info );
  827.         if ( wp == *wpp )
  828.             wpp = &( wp->window.next );
  829.     }
  830.     return( ret );
  831. }
  832.  
  833.  
  834. /*
  835.  *        âìü[âJâïè╓Éö
  836.  */
  837.  
  838. /*  ò`é½Æ╝é╡âCâxâôâgé╠ö¡É╢  */
  839. static    void    SendEventRedraw( wp )
  840. WindowClass    *wp ;
  841. {
  842.     EventInfo    RedrawEvent ;
  843.  
  844.     RedrawEvent.option = EventRedraw ;
  845.     RedrawEvent.x = 0 ;
  846.     RedrawEvent.y = 0 ;
  847.     RedrawEvent.h = wp->clip.x2 - wp->clip.x1 + 1 ;
  848.     RedrawEvent.v = wp->clip.y2 - wp->clip.y1 + 1 ;
  849.     SendEvent( wp->window.id, wp->window.event, wp, & RedrawEvent );
  850. }
  851.  
  852. static    void    SendEventRedrawClip( wp, cp )
  853. WindowClass    *wp ;
  854. ClipClass    *cp ;
  855. {
  856.     EventInfo    RedrawEvent ;
  857.  
  858.     RedrawEvent.option = EventRedraw ;
  859.     RedrawEvent.x = cp->clip.x1 ;
  860.     RedrawEvent.y = cp->clip.y1 ;
  861.     RedrawEvent.h = cp->clip.x2 - cp->clip.x1 + 1 ;
  862.     RedrawEvent.v = cp->clip.y2 - cp->clip.y1 + 1 ;
  863.     SendEvent( wp->window.id, wp->window.event, wp, & RedrawEvent );
  864. }
  865.  
  866. /*    âEâCâôâhâEé╠ò`é½Æ╝é╡  */
  867. static    void    WindowRedrawAll( parent, wp, cp, flag )
  868. WindowClass    *parent, *wp ;
  869. ClipClass    *cp ;
  870. int            flag ;
  871. {
  872.     ClipClass    *saveclip, clip, localclip ;
  873.  
  874.     saveclip = VramClipPtr ;
  875.  
  876.     if ( parent->window.parent == NULL )
  877.         VramClipPtr = cp ;
  878.     else
  879.     {
  880.         VramClipPtr = &clip ;
  881.         WindowClipSet( VramClipPtr, parent, cp );
  882.     }
  883.  
  884.     if ( flag )
  885.     {
  886.         SendEventRedrawClip( parent, cp );
  887.     }
  888.  
  889.     while( wp != NULL )
  890.     {
  891.         if ( ! ( wp->window.attr & WindowAttrInvisible )     &&
  892.              ClipOverlap( &localclip, cp, (ClipClass*)wp )    )
  893.         {
  894.             localclip.clip.x1 -= wp->clip.x1 ;
  895.             localclip.clip.x2 -= wp->clip.x1 ;
  896.             localclip.clip.y1 -= wp->clip.y1 ;
  897.             localclip.clip.y2 -= wp->clip.y1 ;
  898.             SendEventRedrawClip( wp, &localclip );
  899.         }
  900.         wp = wp->window.next ;
  901.     }
  902.     VramClipPtr = saveclip ;
  903. }
  904.  
  905. /*  âEâCâôâhâEâèâXâgé⌐éτé╠ìφÅ£  */
  906. static    void    WindowDeleteList( wp )
  907. WindowClass    *wp ;
  908. {
  909.     WindowClass    *parent, *last, *next ;
  910.  
  911.     parent = wp->window.parent ;
  912.     if ( wp->window.last == NULL )
  913.         parent->window.childtop = wp->window.next ;
  914.     else
  915.     {
  916.         last = wp->window.last ;
  917.         last->window.next = wp->window.next ;
  918.     }
  919.     if ( wp->window.next == NULL )
  920.         parent->window.childbottom = wp->window.last ;
  921.     else
  922.     {
  923.         next = wp->window.next ;
  924.         next->window.last = wp->window.last ;
  925.     }
  926. }
  927.  
  928. /*  âEâCâôâhâEâèâXâgé╠ɵô¬é╓é╠Æ╟ë┴  */
  929. static    void    WindowAppendList( wp )
  930. WindowClass    *wp ;
  931. {
  932.     WindowClass    *parent, *next ;
  933.  
  934.     parent = wp->window.parent ;
  935.  
  936.     wp->window.next = parent->window.childtop ;
  937.     if ( wp->window.next != NULL )
  938.     {
  939.         next = wp->window.next ;
  940.         next->window.last = wp ;
  941.     }
  942.     wp->window.last = NULL ;
  943.     parent->window.childtop = wp ;
  944.     if ( parent->window.childbottom == NULL )
  945.         parent->window.childbottom = wp ;
  946. }
  947.  
  948. /*    ârâàü[â|ü[âgé╠âZâbâg  */
  949. static    void    WindowClipSet( ret, wp, vp )
  950. ClipClass    *ret, *vp ;
  951. WindowClass    *wp ;
  952. {
  953.     int        x, y ;
  954.  
  955.     *ret = *vp ;
  956.     while( wp != NULL )
  957.     {
  958.         x = wp->clip.x1 + wp->window.curclip.clip.x1 ;
  959.         y = wp->clip.y1 + wp->window.curclip.clip.y1 ;
  960.         ret->clip.x1 += x ;
  961.         ret->clip.y1 += y ;
  962.         ret->clip.x2 += x ;
  963.         ret->clip.y2 += y ;
  964.         wp = wp->window.parent ;
  965.     }
  966. }
  967.  
  968. static    int        SetUpClip( ret, vp1, vp2 )
  969. ClipClass    *ret, *vp1, *vp2 ;
  970. {
  971.     if ( vp2->clip.y1 > vp1->clip.y1 )
  972.     {
  973.         ret->clip.y1 = vp1->clip.y1 ;
  974.         ret->clip.y2 = vp2->clip.y1 - 1 ;
  975.         ret->clip.x1 = vp1->clip.x1 ;
  976.         ret->clip.x2 = vp1->clip.x2 ;
  977.         return( TRUE );
  978.     }
  979.     else
  980.         return( FALSE );
  981. }
  982.  
  983. static    int        SetDownClip( ret, vp1, vp2 )
  984. ClipClass    *ret, *vp1, *vp2 ;
  985. {
  986.     if ( vp2->clip.y2 < vp1->clip.y2 )
  987.     {
  988.         ret->clip.y1 = vp2->clip.y2 + 1 ;
  989.         ret->clip.y2 = vp1->clip.y2 ;
  990.         ret->clip.x1 = vp1->clip.x1 ;
  991.         ret->clip.x2 = vp1->clip.x2 ;
  992.         return( TRUE );
  993.     }
  994.     else
  995.         return( FALSE );
  996. }
  997.  
  998. static    int        SetLeftClip( ret, vp1, vp2 )
  999. ClipClass    *ret, *vp1, *vp2 ;
  1000. {
  1001.     if ( vp2->clip.x1 > vp1->clip.x1 )
  1002.     {
  1003.         ret->clip.x1 = vp1->clip.x1 ;
  1004.         ret->clip.x2 = vp2->clip.x1 - 1 ;
  1005.         ret->clip.y1 = max( vp1->clip.y1, vp2->clip.y1 );
  1006.         ret->clip.y2 = min( vp1->clip.y2, vp2->clip.y2 );
  1007.         return( TRUE );
  1008.     }
  1009.     else
  1010.         return( FALSE );
  1011. }
  1012.  
  1013. static    int        SetRightClip( ret, vp1, vp2 )
  1014. ClipClass    *ret, *vp1, *vp2 ;
  1015. {
  1016.     if ( vp2->clip.x2 < vp1->clip.x2 )
  1017.     {
  1018.         ret->clip.x1 = vp2->clip.x2 + 1 ;
  1019.         ret->clip.x2 = vp1->clip.x2 ;
  1020.         ret->clip.y1 = max( vp1->clip.y1, vp2->clip.y1 );
  1021.         ret->clip.y2 = min( vp1->clip.y2, vp2->clip.y2 );
  1022.         return( TRUE );
  1023.     }
  1024.     else
  1025.         return( FALSE );
  1026. }
  1027.  
  1028. /*
  1029.  *        âGâëü[â`âFâbâN
  1030.  */
  1031. void    _ErrorCheck(  msg )
  1032. char    *msg ;
  1033. {
  1034.         if ( WindowError == NULL ){
  1035.             errput( "âGâëü[é¬ö¡É╢é╡é▄é╡é╜: " );    /* 1991 COR. */
  1036.             errput( msg );
  1037.             errput( "\n" );
  1038.             EXIT2( 1 );
  1039.         }else
  1040.             (*WindowError)( msg );
  1041. }
  1042. #if 0
  1043. void    ErrorCheck( flag, msg )
  1044. int        flag ;
  1045. char    *msg ;
  1046. {
  1047.     if ( ! flag )
  1048.     {
  1049.         if ( WindowError == NULL )
  1050.         {
  1051.             errput( "âGâëü[é¬ö¡É╢é╡é▄é╡é╜: " );    /* 1991 COR. */
  1052.             errput( msg );
  1053.             putc( '\n', stderr );
  1054.             exit( 1 );
  1055.         }
  1056.         else
  1057.             (*WindowError)( msg );
  1058.     }
  1059. }
  1060. #endif
  1061.