home *** CD-ROM | disk | FTP | other *** search
/ Kyūkyoku!! X68000 Emulator / X68000Book.dat / mac / OLS / X68000 / Ko-Window / kow142s.lzh / wsrv / stack.c < prev    next >
C/C++ Source or Header  |  1995-11-25  |  4KB  |  184 lines

  1. #include    <stdio.h>
  2. #include    <iocslib.h>
  3. #include    <microstr.h>
  4.  
  5. #include "clip.h"
  6. #include "slider.h"
  7. #include "window.h"
  8. #include "simple.h"
  9. #include "title.h"
  10. #include "manager.h"
  11. #include "stack.h"
  12. #include    "wopen.h"
  13.  
  14. #define    MAX_EVENT_STACK        100
  15. #define    STACK_FONT            12
  16.  
  17. struct    {
  18.         EventType    type;
  19.         int            id;
  20.         char        *name;    /* 1992 10/6 COR.*/
  21.         void        *buf;
  22.     }    EventStack[MAX_EVENT_STACK];
  23.  
  24. int            EventSP;
  25. int            OpenFlag;
  26. TitleClass    StackWP;
  27.  
  28. static    char    *Format[] = {
  29.     "Request : ",
  30.     "Event   : ",
  31.     "Signal  : ",
  32.     "Exec    : ",
  33. } ;
  34.  
  35. /*
  36.     proto -s stack.c > temp
  37. */
  38. static    void    TraceWait( void );
  39. static    int        EventStackEvent( WindowClass*, EventInfo* );
  40.  
  41. /* 1991 COR. */
  42. static void
  43. typeset( type, str, id, name, buf )
  44. EventType    type;
  45. int        id,
  46.         buf;
  47. char    *str,
  48.         *name;
  49. {
  50.         s_strcpy( str, Format[type] );
  51.         itoa2( id, str+10 );
  52.         s_strcat( str, type == TypeRequest ? "  Window" : "  " );
  53.         s_strcat( str, name );
  54.         if( type == TypeSignal ){
  55.             char    obuf[80];
  56.             htoa2( buf, obuf+1 );
  57.             *obuf= ' ';
  58.             s_strcat( str, obuf );
  59.         }
  60. }
  61.  
  62. void
  63. _EventStackPush( type, id, name, buf )
  64. EventType    type ;
  65. int            id ;
  66. char        *name ;
  67. void        *buf ;
  68. {
  69.     EventStack[EventSP].type= type;
  70.     EventStack[EventSP].id= id;
  71.     EventStack[EventSP].name= name;
  72.     EventStack[EventSP].buf= buf;
  73.     if( OpenFlag ){
  74.         DrawBuf    dbuf[1];
  75.         char    str[100];
  76.         typeset( type, str, id, name, buf );    /* 1991 COR. */
  77.         DrawSetSymbol( dbuf, 8, EventSP*STACK_FONT, str, AttrDefault,
  78.                                                         STACK_FONT );
  79.         WindowDraw( (WindowClass*)&StackWP, dbuf, 1 );
  80.     }
  81.     EventSP++;
  82.  
  83.     if( DebugMode & DebugTraceOn )
  84.         TraceWait();
  85. }
  86.  
  87. void
  88. _EventStackPop()
  89. {
  90.     EventSP--;
  91.     if( OpenFlag ){
  92.         DrawBuf    buf[1];
  93.         DrawSetLine( buf, 0, EventSP*STACK_FONT, 300,
  94.                         EventSP*STACK_FONT+STACK_FONT-1, 1, OptionFill );
  95.         WindowDraw( (WindowClass*)&StackWP, buf, 1 );
  96.     }
  97.     if( DebugMode & DebugTraceOn )
  98.         TraceWait();
  99. }
  100.  
  101. static    void
  102. TraceWait()
  103. {
  104.     if( B_SFTSNS() & 0x80 )        /* CAPS */
  105.         return;
  106.     while( ( B_SFTSNS() & 0x81 ) == 0 );    /* CAPS or SHIFT */
  107.     while( B_SFTSNS() & 1 );                /* SHIFT */
  108. }
  109.  
  110. void
  111. EventStackOpen( x, y, h, v )
  112. int        x, y, h, v;
  113. {
  114.     if( OpenFlag == 0 ){
  115.         (*systemfunc[TitleType].setfunc)(
  116.                         &StackWP, x, y, h, v, &RootWindow, "Event Stack",
  117.                             Close|Push|Resize, -1, EventStackEvent );
  118.         WindowSetEventAttr( (WindowClass*)&StackWP,
  119.                                 EventRedrawON|
  120.                                 EventCloseON|
  121.                                 EventMouseSwitchON
  122.         );
  123.         WindowRedraw( (WindowClass*)&StackWP );
  124.     }else{
  125.         WindowMove( (WindowClass*)&StackWP, x, y );
  126.     }
  127.     OpenFlag++;
  128. }
  129.  
  130. void
  131. EventStackClose()
  132. {
  133.     OpenFlag--;
  134.     if( OpenFlag == 0 ){
  135.         OpenFlag= FALSE;
  136.         WindowClose( (WindowClass*)&StackWP );
  137.     }else if( OpenFlag < 0 )
  138.         OpenFlag= 0;
  139. }
  140.  
  141. void
  142. EventStackClear()
  143. {
  144.     DrawBuf    buf[1];
  145.  
  146.     EventSP= 0;
  147.     if( OpenFlag ){
  148.         DrawSetClear( buf, 1 );
  149.         WindowDraw( (WindowClass*)&StackWP, buf, 1 );
  150.     }
  151. }
  152.  
  153. static int
  154. EventStackEvent( wp, info )
  155. WindowClass    *wp;
  156. EventInfo    *info;
  157. {
  158.     int        i;
  159.     DrawBuf    buf[1];
  160.     char    str[100];
  161.  
  162.     switch( info->option ){
  163.         case EventRedraw:
  164.             DrawSetClear( buf, 1 );
  165.             WindowDraw( (WindowClass*)&StackWP, buf, 1 );
  166.             for( i = 0 ; i < EventSP ; ++i ){
  167.                     typeset( EventStack[i].type, str,
  168.                         EventStack[i].id, EventStack[i].name,
  169.                                             EventStack[i].buf );
  170.                 DrawSetSymbol( buf, 8, i*STACK_FONT, str, AttrDefault,
  171.                                                     STACK_FONT );
  172.                 WindowDraw( (WindowClass*)&StackWP, buf, 1 );
  173.             }
  174.             return    TRUE;
  175.         case EventClose:
  176.             EventStackClose();
  177.             return    TRUE;
  178.         default:
  179.             break;
  180.     }
  181.     return    FALSE;
  182. }
  183. /* :vi:se ts=4 sw=4: */
  184.