home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d891 / skew.lha / Skew / source.lha / source / skew_iconify.c < prev    next >
C/C++ Source or Header  |  1993-07-04  |  4KB  |  203 lines

  1. /*
  2.  *        skew_iconify.c
  3.  */
  4.  
  5. #include <exec/types.h>
  6. #include <intuition/intuition.h>
  7. #include <dos/dosextens.h>
  8.  
  9. #include "skew.h"
  10.  
  11. extern     struct Process    *ThisProcess;
  12. extern     struct Window    *Wnd;
  13. extern     struct Screen      *Scr;
  14. extern     struct Gadget     *GList;
  15. extern     APTR            VisualInfo;
  16. extern     APTR             OldWindow;
  17.  
  18. extern VOID CleanUp( LONG );
  19. extern LONG InitDisplay( VOID );
  20.  
  21. BOOL GoodDoubleClick( LONG, ULONG, ULONG );
  22.  
  23.  
  24. VOID
  25. Iconify( VOID )
  26. {
  27.     static LONG left    = 0;
  28.     static LONG top     = 0;
  29.  
  30.     struct NewWindow TinyWindow = {
  31.         left, top,                        /* left, top */
  32.         100, 22,                         /* width,height */
  33.         0, 1,                            /* detailpen, blockpen */
  34.         ( MOUSEBUTTONS | GADGETDOWN | RAWKEY
  35.                                 /* | INTUITICKS | INACTIVEWINDOW */ ),
  36.         ( WINDOWDRAG | RMBTRAP | NOCAREREFRESH | INACTIVEWINDOW),
  37.         NULL,                            /* no custom gadgets */
  38.         NULL,                            /* no custom menu images */
  39.         (UBYTE *)"Skew v1.28",
  40.         NULL,                            /* no custom screen structure */
  41.         NULL,                             /* no superbitmap */
  42.         0, 0, 0, 0,
  43.         PUBLICSCREEN
  44.     };
  45.  
  46.     struct Window        *tinyWnd;
  47.     struct IntuiMessage    *msg;
  48.  
  49.     ULONG  class;
  50.     USHORT code;
  51.     SHORT  old_x = 0, old_y = 0;
  52.     SHORT  new_x, new_y;
  53.     ULONG  seconds, micros;
  54.  
  55.     BOOL fDone = FALSE;
  56.  
  57.     /*
  58.      *    Shut down normal display
  59.      */
  60.       if ( Wnd ) {
  61.         ( (struct Process *)ThisProcess )->pr_WindowPtr = OldWindow;
  62.         CloseWindow( Wnd );
  63.         Wnd = NULL;
  64.       }
  65.  
  66.     if ( GList ) {
  67.         FreeGadgets( GList );
  68.         GList = NULL;
  69.     }
  70.  
  71.     if ( VisualInfo ) {
  72.         FreeVisualInfo( VisualInfo );
  73.         VisualInfo = NULL;
  74.     }
  75.  
  76.     if ( Scr ) {
  77.         CloseScreen( Scr );
  78.         Scr = NULL;
  79.     }
  80.  
  81.     /* open our tiny window */
  82.     tinyWnd = (struct Window *)OpenWindow( &TinyWindow );
  83.     if ( ! tinyWnd ) {
  84.         /* maybe the screen got too small...? */
  85.         left    = 0;
  86.         top        = 0;
  87.         tinyWnd = (struct Window *)OpenWindow( &TinyWindow );
  88.         if ( ! tinyWnd )
  89.             CleanUp( 5L );
  90.     }
  91.  
  92.     while ( ! fDone ) {
  93.         WaitPort( tinyWnd->UserPort );
  94.         while ( msg = (struct IntuiMessage *)GetMsg( tinyWnd->UserPort ) ) {
  95.  
  96.             class    =      msg->Class;
  97.             code    =    msg->Code;
  98.             seconds    =    msg->Seconds;
  99.             micros    =    msg->Micros;
  100.  
  101.             new_x    =    msg->MouseX;
  102.             new_y    =    msg->MouseY;
  103.  
  104.             ReplyMsg( msg );
  105.  
  106.             switch ( class ) {
  107.                 case IDCMP_MOUSEBUTTONS:
  108.                     switch ( code ) {
  109.                         case SELECTDOWN:
  110.                             if ( GoodDoubleClick( 0L, seconds, micros ) )
  111.                                 fDone = TRUE;
  112.                             break;
  113.                         case MENUDOWN:            /* some people use this */
  114.                                 fDone = TRUE;
  115.                             break;
  116.                     }
  117.                     break;
  118.             }
  119.         }
  120.     }
  121.  
  122.     while ( msg = (struct IntuiMessage *)GetMsg( tinyWnd->UserPort ) )
  123.         ReplyMsg( msg );
  124.  
  125.     left    = tinyWnd->LeftEdge;
  126.     top        = tinyWnd->TopEdge;
  127.  
  128.     CloseWindow( tinyWnd );
  129.     if ( ! InitDisplay() )
  130.         CleanUp( 5L );
  131. }
  132.  
  133.  
  134. /* -------------------------------------------------------------
  135.  * returns TRUE if the time you give it was inside the double-click
  136.  * distance from the last time it got
  137.  *
  138.  * ------------------------------------------------------------- */
  139. #define left_button        0L
  140. #define middle_button    1L
  141. #define right_button    2L
  142.  
  143.     BOOL
  144. GoodDoubleClick( LONG button, ULONG secs, ULONG mics )
  145. {
  146.     static ULONG OldLSeconds    = 0L;
  147.     static ULONG OldLMicros        = 0L;
  148.  
  149.     static ULONG OldMSeconds    = 0L;
  150.     static ULONG OldMMicros        = 0L;
  151.  
  152.     static ULONG OldRSeconds    = 0L;
  153.     static ULONG OldRMicros        = 0L;
  154.  
  155.     BOOL ret_val = FALSE;
  156.  
  157.     switch ( button ) {
  158.         case left_button:
  159.             if ( DoubleClick( OldLSeconds, OldLMicros, secs, mics ) ) {
  160.                 OldLSeconds = 0L;
  161.                 OldLMicros    = 0L;
  162.                 ret_val = TRUE;
  163.             } else {
  164.                 OldLSeconds = secs;
  165.                 OldLMicros    = mics;
  166.             }
  167.             OldMSeconds = 0L;
  168.             OldMMicros    = 0L;
  169.             OldRSeconds = 0L;
  170.             OldRMicros    = 0L;
  171.             break;
  172.         case middle_button:
  173.             if ( DoubleClick( OldMSeconds, OldMMicros, secs, mics ) ) {
  174.                 OldMSeconds = 0L;
  175.                 OldMMicros    = 0L;
  176.                 ret_val = TRUE;
  177.             } else {
  178.                 OldMSeconds = secs;
  179.                 OldMMicros    = mics;
  180.             }
  181.             OldLSeconds = 0L;
  182.             OldLMicros    = 0L;
  183.             OldRSeconds = 0L;
  184.             OldRMicros    = 0L;
  185.             break;
  186.         case right_button:
  187.             if ( DoubleClick( OldRSeconds, OldRMicros, secs, mics ) ) {
  188.                 OldRSeconds = 0L;
  189.                 OldRMicros    = 0L;
  190.                 ret_val = TRUE;
  191.             } else {
  192.                 OldRSeconds = secs;
  193.                 OldRMicros    = mics;
  194.             }
  195.             OldLSeconds = 0L;
  196.             OldLMicros    = 0L;
  197.             OldMSeconds = 0L;
  198.             OldMMicros    = 0L;
  199.             break;
  200.     }
  201.     return( ret_val );
  202. }
  203.