home *** CD-ROM | disk | FTP | other *** search
/ Enter 1999 April - Disc 1 / enter_04_1999_1.iso / OS2 / OSMULTI / TRACK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-09  |  5.1 KB  |  220 lines

  1. /*
  2.  * track.c - track focus window
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. #define INCL_PM
  9. #include <os2.h>
  10.  
  11. #include "osmulti2.h"
  12.  
  13. /*
  14.  * Adjustment on Position
  15.  *
  16.  *      posRatio may be changed with in 0..100
  17.  */
  18.  
  19. #define     XPOSRATIO       20      /* 0..100       */
  20. #define     XPOSADJUST      64      /* Bitmap Width */
  21. #define     YPOSADJUST      28
  22.  
  23. int     posRatio   = XPOSRATIO  ;
  24. int     posAdjustX = XPOSADJUST ;
  25. int     posAdjustY = YPOSADJUST ;
  26.  
  27. /*
  28.  * last position
  29.  */
  30.  
  31. static  HWND    lastHwnd = NULLHANDLE ;
  32. static  BOOL    lastShow = FALSE ;
  33. static  SWP     lastSwp  = { 0 } ;
  34.  
  35. /*
  36.  * queryPos - calc. position of bitmap
  37.  */
  38.  
  39. static  void    queryPos(HWND hwnd, PSWP swp)
  40. {
  41.     SWP     pos ;
  42.     
  43.     WinQueryWindowPos(hwnd, &pos) ;
  44.     
  45.     swp->y = pos.y + pos.cy - posAdjustY ;
  46.     if (pos.cx <= posAdjustX) {
  47.         swp->x = pos.x ;
  48.     } else {
  49.         swp->x = pos.x + ((pos.cx - posAdjustX) * posRatio / 100) ;
  50.     }
  51. }
  52.  
  53. /*
  54.  * queryMax - check if maximized window
  55.  */
  56.  
  57. static  BOOL    queryMax(HWND hwnd)
  58. {
  59.     SWP     swpMax ;
  60.     SWP     swpChk ;
  61.     
  62.     WinQueryWindowPos(HWND_DESKTOP, &swpMax) ;
  63.     WinQueryWindowPos(hwnd, &swpChk) ;
  64.     
  65.     if (swpChk.x > swpMax.x) {
  66.         return FALSE ;
  67.     }
  68.     if ((swpChk.x + swpChk.cx) < swpMax.cx) {
  69.         return FALSE ;
  70.     }
  71.     if (swpChk.y > swpMax.y) {
  72.         return FALSE ;
  73.     }
  74.     if ((swpChk.y + swpChk.cy) < swpMax.cy) {
  75.         return FALSE ;
  76.     }
  77.     return TRUE ;   /* checking window covers all desktop */
  78. }
  79.  
  80. /*
  81.  * queryOob - check if out of boundary
  82.  */
  83.  
  84. static  BOOL    queryOob(HWND hwnd)
  85. {
  86.     SWP     swpMax ;
  87.     SWP     swpChk ;
  88.     
  89.     WinQueryWindowPos(HWND_DESKTOP, &swpMax) ;
  90.     WinQueryWindowPos(hwnd, &swpChk) ;
  91.     
  92.     if (swpChk.x >= swpMax.cx) {
  93.         return TRUE ;
  94.     }
  95.     if ((swpChk.x + swpChk.cx) <= 0) {
  96.         return TRUE ;
  97.     }
  98.     if ((swpChk.y + swpChk.cy) >= swpMax.cy) {
  99.         return TRUE ;
  100.     }
  101.     if ((swpChk.y + swpChk.cy) <= 0) {
  102.         return TRUE ;
  103.     }
  104.     return FALSE ;
  105. }
  106.  
  107. /*
  108.  * trackFocus - track Focus Window and Move/Draw
  109.  */
  110.  
  111. void    trackFocus(HAB hab)
  112. {
  113.     HWND    hwndTarget, hwndDesktop ;
  114.     SWP     pos  ;
  115.     BOOL    show, move ;
  116.     BITMAPINFOHEADER2   bmi ;
  117.     
  118.     /*
  119.      * Query Active Window & Position
  120.      */
  121.      
  122.     hwndDesktop = WinQueryDesktopWindow(hab, NULLHANDLE) ;
  123.     hwndTarget  = WinQueryActiveWindow(HWND_DESKTOP)     ;
  124.  
  125.     /* TRACE("trackFocus desktop %08x active %08x\n", hwndDesktop, hwndTarget) ; */
  126.  
  127.     /*
  128.      * if cannot attach to active window, then try old one
  129.      */
  130.      
  131.     if (hwndTarget == NULLHANDLE) {
  132.         hwndTarget = lastHwnd ;
  133.         pos.x = lastSwp.x     ;
  134.     pos.y = lastSwp.y     ;
  135.     } else if (hwndTarget == hwndFrame || hwndTarget == hwndShape) {
  136.         hwndTarget = lastHwnd ;
  137.         pos.x = lastSwp.x     ;
  138.     pos.y = lastSwp.y     ;
  139.     } else if (queryMax(hwndTarget)) {
  140.         hwndTarget = lastHwnd ;
  141.         pos.x = lastSwp.x ;
  142.     pos.y = lastSwp.y ;
  143.     } else if (WinIsWindowShowing(hwndTarget) != TRUE) {
  144.         hwndTarget = lastHwnd ;
  145.         pos.x = lastSwp.x ;
  146.     pos.y = lastSwp.y ;
  147.     } else {
  148.         queryPos(hwndTarget, &pos) ;
  149.     }
  150.     
  151.     /*
  152.      * check if visible
  153.      */
  154.  
  155.     if (hwndTarget == NULLHANDLE) {
  156.         show = FALSE ;
  157.     } else if (hwndTarget == hwndFrame || hwndTarget == hwndShape) {
  158.         show = FALSE ;
  159.     } else if (queryMax(hwndTarget)) {
  160.         show = FALSE ;
  161.     } else if (queryOob(hwndTarget)) {
  162.         show = FALSE ;
  163.     } else {
  164.         show = WinIsWindowShowing(hwndTarget) ;
  165.     }
  166.  
  167.     /*
  168.      * If cannot attach then hide
  169.      */
  170.      
  171.     if (show == FALSE) {
  172.         if (lastShow) {
  173.         TRACE("trackFocus - hide\n") ;
  174.             WinSetWindowPos(hwndFrame, NULLHANDLE, 0, 0, 0, 0, SWP_HIDE) ;
  175.             WinSetWindowPos(hwndShape, NULLHANDLE, 0, 0, 0, 0, SWP_HIDE) ;
  176.             WinSetWindowPos(hwndTalk,  NULLHANDLE, 0, 0, 0, 0, SWP_HIDE) ;
  177.     }
  178.     lastHwnd = NULLHANDLE ;
  179.     lastShow = FALSE      ;
  180.     lastSwp.x = lastSwp.y = 0 ;
  181.     return ;
  182.     }
  183.     
  184.     /*
  185.      * check waht to do, move or re-order
  186.      */
  187.      
  188.     move = FALSE ;      /* always re-order, somtimes move */
  189.     
  190.     if (lastShow == FALSE || hwndTarget != lastHwnd) {
  191.         move = TRUE ;
  192.     }
  193.     if (pos.x != lastSwp.x || pos.y != lastSwp.y) {
  194.         move = TRUE  ;
  195.     }
  196.     
  197.     lastHwnd = hwndTarget ;
  198.     lastShow = TRUE   ;
  199.     lastSwp.x = pos.x ;
  200.     lastSwp.y = pos.y ;
  201.     
  202.     if (move == FALSE) {        /* only to re-order */
  203.         return ;                /* nothing todo with WS_TOPMOST */
  204.     }
  205.     
  206.     /*
  207.      * re-position
  208.      */
  209.      
  210.     bmi.cbFix = sizeof(bmi) ;
  211.     GpiQueryBitmapInfoHeader(hbmMulNorm, &bmi) ;
  212.     WinSetWindowPos(hwndFrame, HWND_TOP, pos.x, pos.y,
  213.             bmi.cx, bmi.cy, (SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_SHOW)) ;
  214. #if 0
  215.     WinSetWindowPos(hwndShape, HWND_TOP, pos.x, pos.y,
  216.             bmi.cx, bmi.cy, (SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_SHOW)) ;
  217. #endif
  218.     balloonMove() ;
  219. }
  220.