Ignore:
Timestamp:
Aug 25, 1999, 5:08:51 PM (26 years ago)
Author:
dengert
Message:

new window size/move code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/new/oslibwin.cpp

    r628 r693  
    1 /* $Id: oslibwin.cpp,v 1.23 1999-08-22 18:29:37 dengert Exp $ */
     1/* $Id: oslibwin.cpp,v 1.24 1999-08-25 15:08:50 dengert Exp $ */
    22/*
    33 * Window API wrappers for OS/2
     
    55 *
    66 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
     7 * Copyright 1999 Daniela Engert (dani@ngrt.de)
    78 *
    89 *
     
    1819
    1920#include <misc.h>
     21#include "win32type.h"
    2022#include <winconst.h>
    2123#include "oslibwin.h"
     
    3133  if(hwndParent == OSLIB_HWND_DESKTOP)
    3234  {
    33         hwndParent = HWND_DESKTOP;
     35        hwndParent = HWND_DESKTOP;
    3436  }
    3537
     
    3941//******************************************************************************
    4042HWND OSLibWinCreateWindow(HWND hwndParent, ULONG dwWinStyle, ULONG dwFrameStyle,
    41                           char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame)
     43                          char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame)
    4244{
    4345 HWND  hwndClient;
     
    4648
    4749  if(pszName && *pszName == 0) {
    48         pszName = NULL;
     50        pszName = NULL;
    4951  }
    5052  if(hwndParent == OSLIB_HWND_DESKTOP) {
    51         hwndParent = HWND_DESKTOP;
     53        hwndParent = HWND_DESKTOP;
    5254  }
    5355  if(Owner == OSLIB_HWND_DESKTOP) {
    54         Owner = HWND_DESKTOP;
     56        Owner = HWND_DESKTOP;
    5557  }
    5658
    5759  if(dwFrameStyle) {
    58         ULONG dwClientStyle;
    59 
    60         dwClientStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
    61         if(pszName)
    62                 dwFrameStyle |= FCF_TITLEBAR;
    63 
    64         dwFrameStyle |= FCF_TASKLIST;
    65         *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
    66                                        &dwFrameStyle, WIN32_STDCLASS,
    67                                        "", dwClientStyle, 0, 0, &hwndClient);
    68         if(*hwndFrame) {
    69                 if(pszName) {
    70                         WinSetWindowText(*hwndFrame, pszName);
    71                 }
    72                 return hwndClient;
    73         }
    74         dprintf(("OSLibWinCreateWindow: WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
    75         return 0;
     60        ULONG dwClientStyle;
     61
     62        dwClientStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
     63        if(pszName)
     64                dwFrameStyle |= FCF_TITLEBAR;
     65
     66        dwFrameStyle |= FCF_TASKLIST;
     67        *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
     68                                       &dwFrameStyle, WIN32_STDCLASS,
     69                                       "", dwClientStyle, 0, 0, &hwndClient);
     70        if(*hwndFrame) {
     71                if(pszName) {
     72                        WinSetWindowText(*hwndFrame, pszName);
     73                }
     74                return hwndClient;
     75        }
     76        dprintf(("OSLibWinCreateWindow: WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
     77        return 0;
    7678  }
    7779  hwndClient = WinCreateWindow(hwndParent, WIN32_STDCLASS, pszName, dwWinStyle, 0, 0, 0, 0,
    78                                Owner, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP, 0, NULL,
    79                                NULL);
     80                               Owner, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP, 0, NULL,
     81                               NULL);
    8082  *hwndFrame = hwndClient;
    8183  return hwndClient;
     
    8587BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
    8688{
    87   *OSWinStyle   = 0;
     89  *OSWinStyle   = 0;
    8890  *OSFrameStyle = 0;
    8991
    9092  /* Window styles */
    9193  if(dwStyle & WS_MINIMIZE_W)
    92         *OSWinStyle |= WS_MINIMIZED;
     94        *OSWinStyle |= WS_MINIMIZED;
    9395//Done explicitely in CreateWindowExA
    9496#if 0
    9597  if(dwStyle & WS_VISIBLE_W)
    96         *OSWinStyle |= WS_VISIBLE;
     98        *OSWinStyle |= WS_VISIBLE;
    9799#endif
    98100  if(dwStyle & WS_DISABLED_W)
    99         *OSWinStyle |= WS_DISABLED;
     101        *OSWinStyle |= WS_DISABLED;
    100102  if(dwStyle & WS_CLIPSIBLINGS_W)
    101         *OSWinStyle |= WS_CLIPSIBLINGS;
     103        *OSWinStyle |= WS_CLIPSIBLINGS;
    102104  if(dwStyle & WS_CLIPCHILDREN_W)
    103         *OSWinStyle |= WS_CLIPCHILDREN;
     105        *OSWinStyle |= WS_CLIPCHILDREN;
    104106  if(dwStyle & WS_MAXIMIZE_W)
    105         *OSWinStyle |= WS_MAXIMIZED;
     107        *OSWinStyle |= WS_MAXIMIZED;
    106108  if(dwStyle & WS_GROUP_W)
    107         *OSWinStyle |= WS_GROUP;
     109        *OSWinStyle |= WS_GROUP;
    108110  if(dwStyle & WS_TABSTOP_W)
    109         *OSWinStyle |= WS_TABSTOP;
     111        *OSWinStyle |= WS_TABSTOP;
    110112
    111113  if(dwStyle & WS_CAPTION_W)
    112         *OSFrameStyle |= FCF_TITLEBAR;
     114        *OSFrameStyle |= FCF_TITLEBAR;
    113115  if(dwStyle & WS_DLGFRAME_W)
    114         *OSFrameStyle |= FCF_DLGBORDER;
     116        *OSFrameStyle |= FCF_DLGBORDER;
    115117  else
    116118  if(dwStyle & WS_BORDER_W)
    117         *OSFrameStyle |= FCF_BORDER;
     119        *OSFrameStyle |= FCF_BORDER;
    118120
    119121  if(dwStyle & WS_VSCROLL_W)
    120         *OSFrameStyle |= FCF_VERTSCROLL;
     122        *OSFrameStyle |= FCF_VERTSCROLL;
    121123  if(dwStyle & WS_HSCROLL_W)
    122         *OSFrameStyle |= FCF_HORZSCROLL;
     124        *OSFrameStyle |= FCF_HORZSCROLL;
    123125  if(dwStyle & WS_SYSMENU_W)
    124         *OSFrameStyle |= FCF_SYSMENU;
     126        *OSFrameStyle |= FCF_SYSMENU;
    125127  if(dwStyle & WS_THICKFRAME_W)
    126         *OSFrameStyle |= FCF_SIZEBORDER;        //??
     128        *OSFrameStyle |= FCF_SIZEBORDER;        //??
    127129  if(dwStyle & WS_MINIMIZEBOX_W)
    128         *OSFrameStyle |= FCF_MINBUTTON;
     130        *OSFrameStyle |= FCF_MINBUTTON;
    129131  if(dwStyle & WS_MAXIMIZEBOX_W)
    130         *OSFrameStyle |= FCF_MAXBUTTON;
     132        *OSFrameStyle |= FCF_MAXBUTTON;
    131133
    132134  if(dwExStyle & WS_EX_DLGMODALFRAME_W)
    133         *OSFrameStyle |= FCF_DLGBORDER;
     135        *OSFrameStyle |= FCF_DLGBORDER;
    134136
    135137  return TRUE;
     
    226228//******************************************************************************
    227229BOOL OSLibWinSetWindowPos(HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y, LONG cx,
    228                           LONG cy, ULONG fl)
     230                          LONG cy, ULONG fl)
    229231{
    230232 HWND hwndParent = hwndInsertBehind;
     
    232234
    233235    if(fl & SWP_MOVE) {
    234         switch(hwndParent)
    235         {
    236             case HWNDOS_TOP:
    237             case HWNDOS_BOTTOM:
    238                 hwndParent = HWND_DESKTOP;
    239                 break;
    240         }
    241         y = MapOS2ToWin32Y(hwndParent, cy, y);
     236        switch(hwndParent)
     237        {
     238            case HWNDOS_TOP:
     239            case HWNDOS_BOTTOM:
     240                hwndParent = HWND_DESKTOP;
     241                break;
     242        }
     243        y = MapOS2ToWin32Y(hwndParent, cy, y);
    242244    }
    243245    rc = WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
     
    247249//******************************************************************************
    248250//******************************************************************************
     251BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
     252{
     253    return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
     254}
     255//******************************************************************************
     256//******************************************************************************
    249257BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
    250258{
     
    252260
    253261  if(fl & SWP_SHOW) {
    254         rc = WinShowWindow(hwnd, TRUE);
     262        rc = WinShowWindow(hwnd, TRUE);
    255263  }
    256264  if(rc == 0)
    257         dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
     265        dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
    258266  rc = WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, fl);
    259267  if(rc == 0)
    260         dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
     268        dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
    261269  return rc;
    262270}
     
    271279BOOL OSLibWinQueryWindowRect(HWND hwnd, PRECT pRect, int RelativeTo)
    272280{
    273  BOOL     rc;
     281 BOOL     rc;
    274282 RECTLOS2 rectl;
    275283
    276284  rc = WinQueryWindowRect(hwnd, (PRECTL)&rectl);
    277285  if(rc) {
    278         if(RelativeTo == RELATIVE_TO_SCREEN) {
    279                 MapOS2ToWin32Rectl(OSLIB_HWND_DESKTOP, hwnd, &rectl, pRect);
    280         }
    281         else    MapOS2ToWin32Rectl(&rectl, pRect);
    282   }
    283   else  memset(pRect, 0, sizeof(RECT));
     286        if(RelativeTo == RELATIVE_TO_SCREEN) {
     287                MapOS2ToWin32Rectl(OSLIB_HWND_DESKTOP, hwnd, &rectl, pRect);
     288        }
     289        else    MapOS2ToWin32Rectl(&rectl, pRect);
     290  }
     291  else  memset(pRect, 0, sizeof(RECT));
    284292  return rc;
    285293}
     
    293301  rc = WinQueryWindowPos(hwnd, &swp);
    294302  if(rc == FALSE) {
    295         dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
    296         return FALSE;
     303        dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
     304        return FALSE;
    297305  }
    298306
    299307  if(swp.fl & SWP_MINIMIZE)
    300         return TRUE;
    301   else  return FALSE;
     308        return TRUE;
     309  else  return FALSE;
    302310}
    303311//******************************************************************************
     
    389397//******************************************************************************
    390398//******************************************************************************
    391 
     399BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
     400{
     401  return WinQueryWindowPos(hwnd, pswp);
     402}
     403//******************************************************************************
     404//******************************************************************************
     405void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld, ULONG parentHeight)
     406{
     407   HWND hWindow            = pswp->hwnd;
     408   HWND hWndInsertAfter    = pswp->hwndInsertBehind;
     409   long x                  = pswp->x;
     410   long y                  = pswp->y;
     411   long cx                 = pswp->cx;
     412   long cy                 = pswp->cy;
     413   UINT fuFlags            = (UINT)pswp->fl;
     414
     415   HWND  hWinAfter;
     416   ULONG flags = 0;
     417
     418   //***************************************************
     419   // Map constant HWNDs (e.g. HWND_DESKTOP, HWND_TOP)
     420   //***************************************************
     421   HWND  hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
     422
     423   if ( hWndInsertAfter == HWND_TOP )
     424      hWinAfter = HWND_TOP_W;
     425   else if ( hWndInsertAfter == HWND_BOTTOM )
     426      hWinAfter = HWND_BOTTOM_W;
     427   else
     428      hWinAfter = (HWND) hWndInsertAfter;
     429
     430   //***********************************
     431   // convert PM flags to Windows flags
     432   //***********************************
     433   if (!(fuFlags & SWP_SIZE))       flags |= SWP_NOSIZE_W;
     434   if (!(fuFlags & SWP_MOVE))       flags |= SWP_NOMOVE_W;
     435   if (!(fuFlags & SWP_ZORDER))     flags |= SWP_NOZORDER_W;
     436   if (  fuFlags & SWP_NOREDRAW)    flags |= SWP_NOREDRAW_W;
     437   if (!(fuFlags & SWP_ACTIVATE))   flags |= SWP_NOACTIVATE_W;
     438   if (  fuFlags & SWP_SHOW)        flags |= SWP_SHOWWINDOW_W;
     439   if (  fuFlags & SWP_HIDE)        flags |= SWP_HIDEWINDOW_W;
     440
     441   //**************************************************************************
     442   // When moving or sizing we'll have to do some calculations for Y inversion.
     443   //
     444   // If moving - invert Y coord.
     445   //
     446   // If sizing - if the height is changing, have to move the window to
     447   //             maintain correct windows position.  If we just size then the
     448   //             TR corner will extend.  The Windows behaviour should be to
     449   //             extend the BR corner.
     450   //
     451   // If this is a child window then we'll have to move within the client
     452   // area of the parent.
     453   //
     454   // If this is an overlapped or popup window we'll have to move around
     455   // within the desktop.
     456   //**************************************************************************
     457   if ( fuFlags & (SWP_MOVE | SWP_SIZE) )
     458   {
     459      if (fuFlags & SWP_SIZE)
     460      {
     461         // If height is changing we MUST move to maintain top-left alignment
     462         if (cy != pswpOld->cy)
     463         {
     464            flags &= ~SWP_NOMOVE_W;
     465         }
     466      }
     467      else
     468      {
     469         cx = pswpOld->cx;
     470         cy = pswpOld->cy;
     471      }
     472
     473      //**********************************************************
     474      // We'll need both a y and cy for the Y inversion code.
     475      // If either wasn't passed in, calculate the current value.
     476      //**********************************************************
     477      if ((fuFlags & SWP_MOVE) == 0)
     478      {
     479         x = pswpOld->x;
     480         y = pswpOld->y;
     481      }
     482
     483      //********************************************************
     484      // Y inversion here... old Y is top left corner of window
     485      // relative to top left of parent.
     486      //********************************************************
     487      y = parentHeight - y - cy;
     488
     489      LONG oldY = parentHeight - pswpOld->y - pswpOld->cy;
     490
     491      // Set the SWP_NOMOVE_W flag if the window has not moved in windows
     492      // coordinates.
     493      if ( ( pswpOld->x == x ) && ( oldY == y ) )
     494         flags |= SWP_NOMOVE_W;
     495
     496      // Set the SWP_NOSIZE_W flag if the window is not really being sized.
     497      if ( ( pswpOld->cx == cx ) && ( pswpOld->cy == cy ) )
     498         flags |= SWP_NOSIZE_W;
     499   }
     500
     501   // Fill in the WINDOWPOS structure with the now calculated PM values.
     502   pwpos->flags            = (UINT)flags;
     503   pwpos->cy               = (int)cy;
     504   pwpos->cx               = (int)cx;
     505   pwpos->x                = (int)x;
     506   pwpos->y                = (int)y;
     507   pwpos->hwndInsertAfter  = hWinAfter;
     508   pwpos->hwnd             = hWindow;
     509}
     510//******************************************************************************
     511//******************************************************************************
     512void OSLibMapWINDOWPOStoSWP(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, ULONG parentHeight)
     513{
     514   HWND hWnd              = pwpos->hwnd;
     515   HWND hWndInsertAfter   = pwpos->hwndInsertAfter;
     516   long x                 = pwpos->x;
     517   long y                 = pwpos->y;
     518   long cx                = pwpos->cx;
     519   long cy                = pwpos->cy;
     520   UINT fuFlags           = pwpos->flags;
     521
     522   HWND  hWinAfter;
     523   ULONG flags = 0;
     524
     525   //***************************************************
     526   // Map constant HWNDs (e.g. HWND_DESKTOP, HWND_TOP)
     527   //***************************************************
     528   HWND  hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
     529
     530   if ( hWndInsertAfter == HWND_TOPMOST_W )
     531//      hWinAfter = HWND_TOPMOST;
     532      hWinAfter = HWND_TOP;
     533   else if ( hWndInsertAfter == HWND_NOTOPMOST_W )
     534//      hWinAfter = HWND_NOTOPMOST;
     535      hWinAfter = HWND_TOP;
     536   else if ( hWndInsertAfter == HWND_TOP_W )
     537      hWinAfter = HWND_TOP;
     538   else if ( hWndInsertAfter == HWND_BOTTOM_W )
     539      hWinAfter = HWND_BOTTOM;
     540   else
     541      hWinAfter = (HWND) hWndInsertAfter;
     542
     543   //***********************************
     544   // convert Windows flags to PM flags
     545   //***********************************
     546   if ( ! ( fuFlags & SWP_NOSIZE_W     ) ) flags |= SWP_SIZE;
     547   if ( ! ( fuFlags & SWP_NOMOVE_W     ) ) flags |= SWP_MOVE;
     548   if ( ! ( fuFlags & SWP_NOZORDER_W   ) ) flags |= SWP_ZORDER;
     549   if (     fuFlags & SWP_NOREDRAW_W   )   flags |= SWP_NOREDRAW;
     550   if ( ! ( fuFlags & SWP_NOACTIVATE_W ) ) flags |= SWP_ACTIVATE;
     551   if (     fuFlags & SWP_SHOWWINDOW_W )   flags |= SWP_SHOW;
     552   if (     fuFlags & SWP_HIDEWINDOW_W )   flags |= SWP_HIDE;
     553   /* no PM equivalent for SWP_FRAMECHANGED_W, SWP_NOCOPYBITS_W and SWP_NOOWNERZORDER_W */
     554
     555   //**************************************************************************
     556   // When moving or sizing we'll have to do some calculations for Y inversion.
     557   //
     558   // If moving - invert Y coord.
     559   //
     560   // If sizing - if the height is changing, have to move the window to
     561   //             maintain correct windows position.  If we just size then the
     562   //             TR corner will extend.  The Windows behaviour should be to
     563   //             extend the BR corner.
     564   //
     565   // If this is a child window then we'll have to move within the client
     566   // area of the parent.
     567   //
     568   // If this is an overlapped or popup window we'll have to move around
     569   // within the desktop.
     570   //**************************************************************************
     571   if ( flags & (SWP_MOVE | SWP_SIZE) )
     572   {
     573      //**********************************************************
     574      // We'll need both a y and cy for the Y inversion code.
     575      // If either wasn't passed in, calculate the current value.
     576      //**********************************************************
     577      if ((flags & SWP_MOVE) == 0)
     578      {
     579         x = pswpOld->x;
     580         y = pswpOld->y;
     581
     582         // If the window is at (x,0) with a height of zero then this calculation
     583         // won't quite work.  Instead of calculating the Windows y coord, we set
     584         // it at (x,0).
     585         if (!(y == 0 && pswpOld->cy == 0))
     586         {
     587            // convert Y coordinate back to Windows's for later conversion with new size
     588            y = parentHeight - y - pswpOld->cy;
     589         }
     590      }
     591
     592      if (flags & SWP_SIZE)
     593      {
     594         // If height is changing we MUST move to maintain top-left alignment
     595         if (cy != pswpOld->cy)
     596            flags |= SWP_MOVE;
     597      }
     598      else
     599      {
     600         cx = pswpOld->cx;
     601         cy = pswpOld->cy;
     602      }
     603
     604      //********************************************************
     605      // Y inversion here... old Y is top left corner of window
     606      // relative to top left of parent.
     607      //********************************************************
     608      y = parentHeight - y - cy;
     609
     610      // Clear the SWP_MOVE flag if the window is not really being moved.
     611      if ( ( pswpOld->x == x ) && ( pswpOld->y == y ) )
     612         flags &= ~SWP_MOVE;
     613
     614      // Clear the SWP_SIZE flag if the window is not really being sized.
     615      if ( ( pswpOld->cx == cx ) && ( pswpOld->cy == cy ) )
     616         flags &= ~SWP_SIZE;
     617   }
     618
     619   // Fill in the WINDOWPOS structure with the now calculated PM values.
     620   pswp->fl               = flags;
     621   pswp->cy               = cy;
     622   pswp->cx               = cx;
     623   pswp->x                = x;
     624   pswp->y                = y;
     625   pswp->hwndInsertBehind = hWinAfter;
     626   pswp->hwnd             = hWindow;
     627   pswp->ulReserved1      = 0;
     628   pswp->ulReserved2      = 0;
     629}
     630//******************************************************************************
     631//******************************************************************************
     632
Note: See TracChangeset for help on using the changeset viewer.