home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_02 / wmsdrag.c < prev    next >
C/C++ Source or Header  |  1991-04-25  |  2KB  |  103 lines

  1. /* WMSDRAG.C - contains routines for dragging windows by a mouse.
  2.  */
  3. #include "wsys.h"
  4.  
  5. static int (*old_trap)(int) = NULL;
  6. static char installed =0;
  7. static int     handle_drag (int); 
  8. static void W_NEAR draw_borders ( int l, int t, int w, int h );
  9. static void W_NEAR remove_borders (void);
  10.  
  11. void wmsdrag (void)        /* install keytrap */
  12.     {
  13.     if ( !installed )
  14.         {
  15.         old_trap = wkeytrap;
  16.         wkeytrap = handle_drag;
  17.         installed = 1;
  18.         }
  19.     return;        /* wmsdrag() */        
  20.     }
  21.     
  22. static int handle_drag (int key)
  23.     {
  24.     int     l, t,                    /* new top and bottom */ 
  25.             w, h;                    /* width and height */  
  26.     int done;    
  27.     
  28.  
  29.     /* did user 1) click left mouse button 2) on upper left corner of frame
  30.      *            and 3) is this window draggable ?
  31.      */
  32.     if     (  ( key==MOUSE ) && ( wmouse.wms_used & WMS_LEFT_PRS ) 
  33.         && ( wmouse.wms_x == -1 ) && ( wmouse.wms_y == -1 ) 
  34.         && (w0->winbox !=0) && ( w0-> winsave != NULL )
  35.         )
  36.         {
  37.         w = w0-> winxmax +3;        /* actual # of columns + 2 for border */
  38.         h = w0-> winymax +3;
  39.  
  40.         done = 0;    
  41.  
  42.         draw_borders ( wmouse.wms_xabs, wmouse.wms_yabs, w, h );
  43.         do 
  44.             {
  45.         
  46.             wmouse_location ();
  47.             l = wmouse.wms_xabs;
  48.             t = wmouse.wms_yabs;
  49.  
  50.             if ( (l+w+1 < wxabsmax) && (t+h+1 < wyabsmax) )
  51.                 {
  52.                 /* remove prev. borders and redraw in new location */
  53.                 remove_borders ();
  54.                 draw_borders ( l,t,w,h );
  55.                 }
  56.             done = wmouse.wms_used & (WMS_LEFT_RLS | WMS_RIGHT_RLS );
  57.                 
  58.             }
  59.         while ( ! done );    /* end do () */
  60.         remove_borders ();
  61.                 
  62.         if ( 0== (done & WMS_RIGHT_RLS ) )
  63.             {
  64.             wrelocate ( l+1, t+1 );        /* move current window */
  65.             }     
  66.         key = 0;
  67.         
  68.         wmouse_flush ();        
  69.         }
  70.     else
  71.     if ( old_trap != NULL )
  72.         {
  73.         key = (*old_trap)(key);        /* chain previous handler */
  74.         }    
  75.     
  76.     return (key);        /* handle_drag () */
  77.     }
  78.     
  79. static void W_NEAR draw_borders ( int l, int t, int w, int h )
  80.     {
  81.     int r, b;
  82.     r = l + w -1;
  83.     b = t + h -1;    
  84.  
  85.     wopen (l, t, 1, h, LIGHTGRAY, NO_BORDER, 0, WSAVE2RAM );         
  86.     wsetc ( 247 );
  87.     wopen (l,  t, w, 1, LIGHTGRAY, NO_BORDER, 0, WSAVE2RAM );         
  88.     wsetc ( 247 );
  89.     wopen (r, t, 1, h, LIGHTGRAY, NO_BORDER, 0, WSAVE2RAM );         
  90.     wsetc ( 247 );
  91.     wopen (l, b, w, 1, LIGHTGRAY, NO_BORDER, 0, WSAVE2RAM );         
  92.     wsetc ( 247 );
  93.     return;        /* draw_borders */
  94.     }    
  95.     
  96.     
  97. static void W_NEAR remove_borders (void)
  98.     {
  99.     wclose(), wclose(), wclose(), wclose();
  100.     return;
  101.     }
  102. /*------------------ end of WMSDRAG.C ----------------*/
  103.