home *** CD-ROM | disk | FTP | other *** search
/ Kyūkyoku!! X68000 Emulator / X68000Book.dat / mac / OLS / X68000 / Ko-Window / kow142s.lzh / parts / iconman.c < prev    next >
C/C++ Source or Header  |  1992-12-13  |  3KB  |  169 lines

  1. /*    Iconmanager +10 âTâôâvâï    */
  2. /*    1992 by H.Ogasawara (COR.)    */
  3.  
  4. #include    <corlib.h>
  5. #include    <winop.h>
  6.  
  7. /* ÄΦö▓é½âvâìâOâëâÇé╛é»é╟âTâôâvâïé┼é╖ */
  8.  
  9. #define    HSIZE    80
  10. #define    VSIZE    80
  11. #define    XOFFSET    2
  12. #define    YOFFSET    2
  13.  
  14. #define    C(msg)        {ConsoleOpen();ConsolePrint(msg);}
  15.  
  16. typedef    struct icontbl {
  17.     WindowID    wp;
  18.     int        x, y, h;
  19.     struct icontbl    *next;
  20. } IconTbl;
  21.  
  22. IconTbl    *Top= NULL;
  23. int    GlobalX= 1;
  24. int    WindowHeapSize= 1024;
  25.  
  26. /* âeü[âuâïÆ╟ë┴ */
  27. IconTbl *
  28. alloc_tbl( wp, x, y, h )
  29. WindowID    wp;
  30. {
  31.  
  32.     IconTbl    *it;
  33.     if( it= (IconTbl*)WindowMemoryAlloc( sizeof(IconTbl) ) ){
  34.         it->next= Top;
  35.         Top= it;
  36.         it->wp= wp;
  37.         it->x= x;
  38.         it->y= y;
  39.         it->h= h;
  40.         return    it;
  41.     }
  42.     return    NULL;
  43. }
  44.  
  45. /* âeü[âuâïèJò· */
  46. free_tbl( wp )
  47. WindowID    wp;
  48. {
  49.     IconTbl    *it= Top,
  50.         **pt= &Top;
  51.     for(; it ; pt= &it->next, it= it->next ){
  52.         if( wp == it->wp ){
  53.             *pt= it->next;
  54.             WindowMemoryFree( it );
  55.             break;
  56.         }
  57.     }
  58. }
  59.  
  60. /* âeü[âuâïë≡Å£ */
  61. free_tbl_all()
  62. {
  63.     IconTbl    *it= Top, *pt;
  64.     for(; it ; it= pt ){
  65.         pt= it->next;
  66.         WindowMemoryFree( it );
  67.     }
  68. }
  69.  
  70. /* ï≤é½ÅΩÅèâ`âFâbâN */
  71. check_tbl_width( x, h )
  72. {
  73.     IconTbl    *it= Top;
  74.     for(; it ; it= it->next ){
  75.         if( (it->x > x && it->x < x+h) ||
  76.             (it->x+it->h > x && it->x+it->h < x+h) )
  77.                 return    FALSE;
  78.     }
  79.     return    TRUE;
  80. }
  81.  
  82. /* ï≤é½ÅΩÅèé≡ÆTé╖ */
  83. search_tbl_position( h )
  84. {
  85.     IconTbl    *it= Top;
  86.     for(; it ; it= it->next ){
  87.         if( check_tbl_width( it->x+it->h+  2  , h ) )
  88.             return    it->x+it->h+2;
  89.     }
  90.     return    XOFFSET;
  91. }
  92.  
  93. /* âAâCâRâôë╗âïü[â`âô */
  94. IconifyExec( wp, h, v, exec, px, py )
  95. WindowID    wp;
  96. int        h, v;
  97. int        (*exec)();
  98. int        *px, *py;
  99. {
  100.     int    x;
  101.     C( "sono1\r\n" );
  102.     if( x= search_tbl_position( h ) ){
  103.         C( "sono2\r\n" );
  104.         *px= x;
  105.         *py= YOFFSET;
  106.         C( "sono3\r\n" );
  107.         alloc_tbl( wp, *px, *py, h );
  108.         C( "sono4\r\n" );
  109.     }
  110.     return    FALSE;
  111. }
  112.  
  113. /* âAâCâRâôâ}âEâXâïü[â`âô */
  114. IconMouseExec( wp, info, f )
  115. WindowID    wp;
  116. EventInfo    *info;
  117. int        *f;
  118. {
  119.     *f= TRUE;
  120.     free_tbl( wp );
  121.     return    FALSE;
  122. }
  123.  
  124. IconManagerInit()
  125. {
  126.     IconMan    *ip;
  127.     if( !WindowGetCommon( "IconManExec", 0 ) ){
  128.         if( ip= WindowGetCommon( "IconManExec", sizeof(IconMan) ) ){
  129.             ip->iconifyexec= IconifyExec;
  130.             ip->iconmouseexec= IconMouseExec;
  131.         }
  132.         return    TRUE;
  133.     }else{
  134.         ConsoleOpen();
  135.         ConsolePrint( "iconman:é╖é┼é╔æ╝é╠iconmané¬æ╢ì▌é╡é▄é╖\r\n" );
  136.         return    FALSE;
  137.     }
  138. }
  139.  
  140. Exec( wp, info )
  141. WindowID    wp;
  142. EventInfo    *info;
  143. {
  144.     DrawBuf    dbuf[1];
  145.     switch( info->option ){
  146.     case EventRedraw:
  147.         DrawSetClear( dbuf, 1 );
  148.         WindowDraw( wp, dbuf, 1 );
  149.         return    TRUE;
  150.     case EventClose:    /* â}âlü[âWââé╠ëεôⁿé≡ë≡Å£ */
  151.         WindowResetCommon( "IconManExec" );
  152.         free_tbl_all();
  153.         return    FALSE;
  154.     }
  155.     return    FALSE;
  156. }
  157.  
  158. WindowMain( argc, argv )
  159. char    **argv;
  160. {
  161.     /* âTâôâvâïé╚é╠é┼üAÄΦö▓é½é╡é─ MgLIB é≡Ägé┴é─é▄é╖ */
  162.     if( IconManagerInit() )
  163.         MgWindowDefaultOpenArgs( 10, 10, HSIZE, VSIZE,
  164.                     "IconMan", argc, argv, 0, Exec );
  165.     else
  166.         WindowSendSignal( WindowProcessID, SignalKill, 0 );
  167. }
  168.  
  169.