home *** CD-ROM | disk | FTP | other *** search
- /*
- * track.c - track focus window
- */
-
- #include <stdio.h>
- #include <stdlib.h>
-
- #define INCL_PM
- #include <os2.h>
-
- #include "osmulti2.h"
-
- /*
- * Adjustment on Position
- *
- * posRatio may be changed with in 0..100
- */
-
- #define XPOSRATIO 20 /* 0..100 */
- #define XPOSADJUST 64 /* Bitmap Width */
- #define YPOSADJUST 28
-
- int posRatio = XPOSRATIO ;
- int posAdjustX = XPOSADJUST ;
- int posAdjustY = YPOSADJUST ;
-
- /*
- * last position
- */
-
- static HWND lastHwnd = NULLHANDLE ;
- static BOOL lastShow = FALSE ;
- static SWP lastSwp = { 0 } ;
-
- /*
- * queryPos - calc. position of bitmap
- */
-
- static void queryPos(HWND hwnd, PSWP swp)
- {
- SWP pos ;
-
- WinQueryWindowPos(hwnd, &pos) ;
-
- swp->y = pos.y + pos.cy - posAdjustY ;
- if (pos.cx <= posAdjustX) {
- swp->x = pos.x ;
- } else {
- swp->x = pos.x + ((pos.cx - posAdjustX) * posRatio / 100) ;
- }
- }
-
- /*
- * queryMax - check if maximized window
- */
-
- static BOOL queryMax(HWND hwnd)
- {
- SWP swpMax ;
- SWP swpChk ;
-
- WinQueryWindowPos(HWND_DESKTOP, &swpMax) ;
- WinQueryWindowPos(hwnd, &swpChk) ;
-
- if (swpChk.x > swpMax.x) {
- return FALSE ;
- }
- if ((swpChk.x + swpChk.cx) < swpMax.cx) {
- return FALSE ;
- }
- if (swpChk.y > swpMax.y) {
- return FALSE ;
- }
- if ((swpChk.y + swpChk.cy) < swpMax.cy) {
- return FALSE ;
- }
- return TRUE ; /* checking window covers all desktop */
- }
-
- /*
- * queryOob - check if out of boundary
- */
-
- static BOOL queryOob(HWND hwnd)
- {
- SWP swpMax ;
- SWP swpChk ;
-
- WinQueryWindowPos(HWND_DESKTOP, &swpMax) ;
- WinQueryWindowPos(hwnd, &swpChk) ;
-
- if (swpChk.x >= swpMax.cx) {
- return TRUE ;
- }
- if ((swpChk.x + swpChk.cx) <= 0) {
- return TRUE ;
- }
- if ((swpChk.y + swpChk.cy) >= swpMax.cy) {
- return TRUE ;
- }
- if ((swpChk.y + swpChk.cy) <= 0) {
- return TRUE ;
- }
- return FALSE ;
- }
-
- /*
- * trackFocus - track Focus Window and Move/Draw
- */
-
- void trackFocus(HAB hab)
- {
- HWND hwndTarget, hwndDesktop ;
- SWP pos ;
- BOOL show, move ;
- BITMAPINFOHEADER2 bmi ;
-
- /*
- * Query Active Window & Position
- */
-
- hwndDesktop = WinQueryDesktopWindow(hab, NULLHANDLE) ;
- hwndTarget = WinQueryActiveWindow(HWND_DESKTOP) ;
-
- /* TRACE("trackFocus desktop %08x active %08x\n", hwndDesktop, hwndTarget) ; */
-
- /*
- * if cannot attach to active window, then try old one
- */
-
- if (hwndTarget == NULLHANDLE) {
- hwndTarget = lastHwnd ;
- pos.x = lastSwp.x ;
- pos.y = lastSwp.y ;
- } else if (hwndTarget == hwndFrame || hwndTarget == hwndShape) {
- hwndTarget = lastHwnd ;
- pos.x = lastSwp.x ;
- pos.y = lastSwp.y ;
- } else if (queryMax(hwndTarget)) {
- hwndTarget = lastHwnd ;
- pos.x = lastSwp.x ;
- pos.y = lastSwp.y ;
- } else if (WinIsWindowShowing(hwndTarget) != TRUE) {
- hwndTarget = lastHwnd ;
- pos.x = lastSwp.x ;
- pos.y = lastSwp.y ;
- } else {
- queryPos(hwndTarget, &pos) ;
- }
-
- /*
- * check if visible
- */
-
- if (hwndTarget == NULLHANDLE) {
- show = FALSE ;
- } else if (hwndTarget == hwndFrame || hwndTarget == hwndShape) {
- show = FALSE ;
- } else if (queryMax(hwndTarget)) {
- show = FALSE ;
- } else if (queryOob(hwndTarget)) {
- show = FALSE ;
- } else {
- show = WinIsWindowShowing(hwndTarget) ;
- }
-
- /*
- * If cannot attach then hide
- */
-
- if (show == FALSE) {
- if (lastShow) {
- TRACE("trackFocus - hide\n") ;
- WinSetWindowPos(hwndFrame, NULLHANDLE, 0, 0, 0, 0, SWP_HIDE) ;
- WinSetWindowPos(hwndShape, NULLHANDLE, 0, 0, 0, 0, SWP_HIDE) ;
- WinSetWindowPos(hwndTalk, NULLHANDLE, 0, 0, 0, 0, SWP_HIDE) ;
- }
- lastHwnd = NULLHANDLE ;
- lastShow = FALSE ;
- lastSwp.x = lastSwp.y = 0 ;
- return ;
- }
-
- /*
- * check waht to do, move or re-order
- */
-
- move = FALSE ; /* always re-order, somtimes move */
-
- if (lastShow == FALSE || hwndTarget != lastHwnd) {
- move = TRUE ;
- }
- if (pos.x != lastSwp.x || pos.y != lastSwp.y) {
- move = TRUE ;
- }
-
- lastHwnd = hwndTarget ;
- lastShow = TRUE ;
- lastSwp.x = pos.x ;
- lastSwp.y = pos.y ;
-
- if (move == FALSE) { /* only to re-order */
- return ; /* nothing todo with WS_TOPMOST */
- }
-
- /*
- * re-position
- */
-
- bmi.cbFix = sizeof(bmi) ;
- GpiQueryBitmapInfoHeader(hbmMulNorm, &bmi) ;
- WinSetWindowPos(hwndFrame, HWND_TOP, pos.x, pos.y,
- bmi.cx, bmi.cy, (SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_SHOW)) ;
- #if 0
- WinSetWindowPos(hwndShape, HWND_TOP, pos.x, pos.y,
- bmi.cx, bmi.cy, (SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_SHOW)) ;
- #endif
- balloonMove() ;
- }
-