home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlib_ResizeWindow.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  9KB  |  292 lines

  1.  
  2. #include "Xlib_private.h"
  3.  
  4. int SizeClient(HWND hwnd, int width, int height) 
  5. {
  6.     DBUG_ENTER("SizeClient")
  7.     Xlib_SetWindowPos SizeParams = { hwnd, NULLHANDLE,
  8.         0, 0, width, height, SWP_SIZE
  9.     };
  10.     int result = (int)WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0);
  11.     DBUG_RETURN(result);
  12. }
  13.  
  14. int XResizeWindow(Display* display, Window w, unsigned int width,unsigned int height)
  15. {
  16.     DBUG_ENTER("XResizeWindow")
  17.     XWindowAttributes *winattrib = GetWinAttrib(w,NULL);
  18.     HWND winframe = WinQueryWindowULong((HWND)w, QWP_FRAMEHWND);
  19.     HWND winparent = WinQueryWindow(winframe, QW_PARENT);
  20.     Xlib_SetWindowPos SizeParams = { winframe, NULLHANDLE,
  21.         0, 0, width, height, SWP_MOVE | SWP_SIZE
  22.     };
  23.     SWP swp, parent;
  24.     
  25.     if (!winframe || !winattrib ||
  26.         !WinQueryWindowPos(winframe, &swp) ||
  27.         !WinQueryWindowPos(winparent, &parent)) DBUG_RETURN(False);
  28.     if (winframe != (HWND)w) {
  29.         SizeClient((HWND)w, width, height);
  30.         SizeParams.cx += 2 * winattrib->border_width;
  31.         SizeParams.cy += 2 * winattrib->border_width + 
  32.             WinQuerySysValue(hwndDesktop,SV_CYTITLEBAR);
  33.         SizeParams.y = parent.cy - winattrib->y - height - winattrib->border_width;
  34.     } else
  35.     SizeParams.y = parent.cy - winattrib->y - height;
  36.     SizeParams.x = swp.x;
  37.     if (WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0)) {
  38.         winattrib->width = width;
  39.         winattrib->height = height;
  40.         DBUG_RETURN(True);
  41.     } else
  42.         DBUG_RETURN(False);
  43. }
  44.  
  45. int XMoveWindow(Display* display, Window w, int x, int y)
  46. {
  47.     DBUG_ENTER("XMoveWindow")
  48.     XWindowAttributes *winattrib = GetWinAttrib(w,NULL);
  49.     HWND winframe = WinQueryWindowULong((HWND)w, QWP_FRAMEHWND);
  50.     HWND winparent = WinQueryWindow(winframe, QW_PARENT);
  51.     Xlib_SetWindowPos SizeParams = { winframe, NULLHANDLE,
  52.         x, 0, 0, 0, SWP_MOVE
  53.     };
  54.     SWP swp, parent;
  55.  
  56.     if (!winframe || !winattrib ||
  57.         !WinQueryWindowPos(winframe, &swp) ||
  58.         !WinQueryWindowPos(winparent, &parent)) DBUG_RETURN(False);
  59.     if ( winframe != (HWND)w) {
  60.         SizeParams.x -= winattrib->border_width;
  61.         SizeParams.y = parent.cy - y - swp.cy - winattrib->border_width;
  62.     } else
  63.     SizeParams.y = parent.cy - y - swp.cy;
  64.     if (WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0)) {
  65.         winattrib->x = x;
  66.         winattrib->y = y;
  67.         DBUG_RETURN(True);
  68.     } else
  69.         DBUG_RETURN(False);
  70. }
  71.  
  72. int XMoveResizeWindow(Display* display, Window w, int x, int y, unsigned int width, unsigned int height)
  73. {
  74.     DBUG_ENTER("XMoveResizeWindow")
  75.     XWindowAttributes *winattrib = GetWinAttrib(w,NULL);
  76.     HWND winframe = WinQueryWindowULong((HWND)w, QWP_FRAMEHWND);
  77.     HWND winparent = WinQueryWindow(winframe, QW_PARENT);
  78.     Xlib_SetWindowPos SizeParams = { winframe, NULLHANDLE,
  79.         x, 0, width, height, SWP_MOVE | SWP_SIZE
  80.     };
  81.     SWP swp, parent;
  82.  
  83.     if (!winframe || !winattrib ||
  84.         !WinQueryWindowPos(winframe, &swp) ||
  85.         !WinQueryWindowPos(winparent, &parent)) DBUG_RETURN(False);
  86.     if (winframe != (HWND)w) {
  87.         SizeClient((HWND)w, width, height);
  88.         SizeParams.cx += 2 * winattrib->border_width;
  89.         SizeParams.cy += 2 * winattrib->border_width + 
  90.             WinQuerySysValue(hwndDesktop,SV_CYTITLEBAR);
  91.         SizeParams.x -= winattrib->border_width;
  92.         SizeParams.y = parent.cy - y - height - winattrib->border_width;
  93.     } else
  94.     SizeParams.y = parent.cy - y - height;
  95.     if (WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0)) {
  96.         winattrib->x = x;
  97.         winattrib->y = y;
  98.         winattrib->width = width;
  99.         winattrib->height = height;
  100.         DBUG_RETURN(True);
  101.     } else
  102.         DBUG_RETURN(False);
  103. }
  104.  
  105. int XMapWindow(Display* display, Window w)
  106. {
  107.     DBUG_ENTER("XMapWindow")
  108.     XWindowAttributes *winattrib = GetWinAttrib(w,NULL);
  109.     HWND winframe = WinQueryWindowULong((HWND)w, QWP_FRAMEHWND);
  110.     Xlib_SetWindowPos SizeParams = { winframe, NULLHANDLE,
  111.         0, 0, 0, 0, SWP_SHOW
  112.     };
  113.     int result;
  114.     if (!winframe || !winattrib) DBUG_RETURN(False);
  115.     winattrib->map_state = IsUnmapped;
  116.     if (winframe != (HWND)w) SizeParams.fl |= SWP_ACTIVATE;
  117.     result = (int)WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0);
  118.     DBUG_RETURN(result);
  119. }
  120.  
  121. int XMapSubwindows(Display *display, Window w)
  122. {
  123.     DBUG_ENTER("XMapSubwindows")
  124.     HENUM henum;
  125.     HWND child;
  126.     henum = WinBeginEnumWindows((HWND)w);
  127.     while((child = WinGetNextWindow(henum)) != NULLHANDLE)
  128.         XMapWindow(display, (Window)child);
  129.     DBUG_RETURN(WinEndEnumWindows(henum));
  130. }
  131.  
  132. int XUnmapWindow(Display* display, Window w)
  133. {
  134.     DBUG_ENTER("XUnmapWindow")
  135.     XWindowAttributes *winattrib = GetWinAttrib(w,NULL);
  136.     HWND winframe = WinQueryWindowULong((HWND)w, QWP_FRAMEHWND);
  137.     Xlib_SetWindowPos SizeParams = { winframe, NULLHANDLE,
  138.         0, 0, 0, 0, SWP_HIDE
  139.     };
  140.     int result;
  141.     if (!winframe || !winattrib) DBUG_RETURN(False);
  142.     winattrib->map_state = IsUnmapped;
  143.     result = (int)WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0);
  144.     DBUG_RETURN(result);
  145. }
  146.  
  147. Status XWithdrawWindow(Display* display, Window w, int screen_number)
  148. {
  149.     DBUG_ENTER("XWithdrawWindow")
  150.     XWindowAttributes *winattrib = GetWinAttrib(w,NULL);
  151.     HWND winframe = WinQueryWindowULong((HWND)w, QWP_FRAMEHWND);
  152.     Xlib_SetWindowPos SizeParams = { winframe, NULLHANDLE,
  153.         0, 0, 0, 0, SWP_HIDE
  154.     };
  155.     int result;
  156.     if (!winframe || !winattrib) DBUG_RETURN(False);
  157.     winattrib->map_state = IsUnmapped;
  158.     if (winframe != (HWND)w) SizeParams.fl |= SWP_DEACTIVATE;
  159.     result = (int)WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0);
  160.     DBUG_RETURN(result);
  161. }
  162.  
  163. int XUnmapSubwindows(Display *display, Window w)
  164. {
  165.     DBUG_ENTER("XUnmapSubwindows")
  166.     HENUM henum;
  167.     HWND child;
  168.     henum = WinBeginEnumWindows((HWND)w);
  169.     while((child = WinGetNextWindow(henum)) != NULLHANDLE)
  170.         XUnmapWindow(display, (Window)child);
  171.     DBUG_RETURN(WinEndEnumWindows(henum));
  172. }
  173.  
  174. int XMapRaised(Display* display, Window w)
  175. {
  176.     DBUG_ENTER("XMapRaised")
  177.     XWindowAttributes *winattrib = GetWinAttrib(w,NULL);
  178.     HWND winframe = WinQueryWindowULong((HWND)w, QWP_FRAMEHWND);
  179.     Xlib_SetWindowPos SizeParams = { winframe, HWND_TOP,
  180.         0, 0, 0, 0, SWP_SHOW | SWP_ZORDER
  181.     };
  182.     if (!winframe || !winattrib) DBUG_RETURN(False);
  183.     winattrib->map_state = IsUnmapped;
  184.     {
  185.         int result = (int)WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0);
  186.         DBUG_RETURN(result);
  187.     }
  188. }
  189.  
  190. int XRaiseWindow(Display* display, Window w)
  191. {
  192.     DBUG_ENTER("XRaiseWindow")
  193.     HWND winframe = WinQueryWindowULong((HWND)w, QWP_FRAMEHWND);
  194.     Xlib_SetWindowPos SizeParams = { winframe, HWND_TOP,
  195.         0, 0, 0, 0, SWP_ZORDER
  196.     };
  197.     if (winframe && WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0))
  198.         DBUG_RETURN(True);
  199.     
  200.     DBUG_RETURN(False);
  201. }
  202.  
  203. int XLowerWindow(Display* display, Window w)
  204. {
  205.     DBUG_ENTER("XLowerWindow")
  206.     HWND winframe = WinQueryWindowULong((HWND)w, QWP_FRAMEHWND);
  207.     Xlib_SetWindowPos SizeParams = { winframe, HWND_BOTTOM,
  208.         0, 0, 0, 0, SWP_ZORDER
  209.     };
  210.     if (winframe && WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0))
  211.         DBUG_RETURN(True);
  212.     
  213.     DBUG_RETURN(False);
  214. }
  215.  
  216. int XCirculateSubwindows(Display *display, Window w, int direction)
  217. {
  218.     DBUG_ENTER("XCirculateSubwindows")
  219.     /* todo: determine windows which are completely exposed
  220.        and remove them from the list */
  221.     HENUM henum;
  222.     HWND child;
  223.     henum = WinBeginEnumWindows((HWND)w);
  224.     if(direction == LowerHighest)
  225.     {
  226.         if((child = WinGetNextWindow(henum)) != NULLHANDLE)
  227.         XRaiseWindow(display, w);
  228.     }
  229.     else if(direction == RaiseLowest)
  230.     {
  231.         while((child = WinGetNextWindow(henum)) != NULLHANDLE) { } 
  232.         if(child)
  233.             XLowerWindow(display, w);
  234.     }
  235.     DBUG_RETURN(WinEndEnumWindows(henum));
  236. }
  237.  
  238. int XCirculateSubwindowsDown(Display *display, Window w)
  239. {
  240.     DBUG_ENTER("XCirculateSubwindowsDown")
  241.     int result = XCirculateSubwindows(display, w, LowerHighest);
  242.     DBUG_RETURN(result);
  243. }
  244.  
  245. int XCirculateSubwindowsUp(Display *display, Window w)
  246. {
  247.     DBUG_ENTER("XCirculateSubwindowsUp")
  248.     int result = XCirculateSubwindows(display, w, RaiseLowest);
  249.     DBUG_RETURN(result);
  250. }
  251.  
  252. Status XIconifyWindow(Display *display, Window w, int screen_number)
  253. {
  254.    DBUG_ENTER("XIconifyWindow")
  255.     Xlib_SetWindowPos SizeParams = { WinQueryWindowULong((HWND)w, QWP_FRAMEHWND), NULLHANDLE,
  256.         0, 0, 0, 0, SWP_MINIMIZE };
  257.    if (!SizeParams.hwnd)
  258.       DBUG_RETURN(False);
  259.    WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0);
  260.    DBUG_RETURN(True);
  261. }
  262.  
  263. int XReparentWindow(display, w, parent, x, y)
  264.       Display *display;
  265.       Window w;
  266.       Window parent;
  267.       int x, y;
  268. {
  269.    DBUG_ENTER("XReparentWindow")
  270.    WinSetParent(w, parent, FALSE);
  271.    XMoveWindow(display, w, x, y);
  272.    DBUG_RETURN(True);
  273. }
  274.  
  275. int XRestackWindows(display, windows, nwindows)
  276.       Display *display;
  277.       Window windows[];
  278.       int nwindows;
  279. {
  280.    DBUG_ENTER("XRestackWindows")
  281.     Xlib_SetWindowPos SizeParams = { NULLHANDLE, HWND_BOTTOM,
  282.         0, 0, 0, 0, SWP_ZORDER };
  283.    int i;
  284.    for(i=nwindows;i>0;i--)
  285.       {
  286.         SizeParams.hwnd = WinQueryWindowULong((HWND)windows[i], QWP_FRAMEHWND);
  287.         if (SizeParams.hwnd) 
  288.            WinSendMsg(mainhwnd, UM_SetWindowPos, (MPARAM)&SizeParams, 0);
  289.       }
  290.    DBUG_RETURN(True);
  291. }
  292.