| 1 | /* $Id: oslibwin.cpp,v 1.109 2001-10-15 17:09:03 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Window API wrappers for OS/2 | 
|---|
| 4 | * | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * Copyright 1999 Daniela Engert (dani@ngrt.de) | 
|---|
| 8 | * | 
|---|
| 9 | * | 
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 11 | * | 
|---|
| 12 | */ | 
|---|
| 13 | #define  INCL_WIN | 
|---|
| 14 | #define  INCL_PM | 
|---|
| 15 | #define  INCL_WINSWITCHLIST | 
|---|
| 16 | #include <os2wrap.h> | 
|---|
| 17 | #include <stdlib.h> | 
|---|
| 18 | #include <string.h> | 
|---|
| 19 |  | 
|---|
| 20 | #include <misc.h> | 
|---|
| 21 | #include <win32type.h> | 
|---|
| 22 | #include <winconst.h> | 
|---|
| 23 | #include <winuser32.h> | 
|---|
| 24 | #include "oslibwin.h" | 
|---|
| 25 | #include "oslibutil.h" | 
|---|
| 26 | #include "oslibmsg.h" | 
|---|
| 27 | #include "oslibgdi.h" | 
|---|
| 28 | #include "pmwindow.h" | 
|---|
| 29 | #include "initterm.h" | 
|---|
| 30 |  | 
|---|
| 31 | #define DBG_LOCALLOG    DBG_oslibwin | 
|---|
| 32 | #include "dbglocal.h" | 
|---|
| 33 |  | 
|---|
| 34 | //****************************************************************************** | 
|---|
| 35 | //****************************************************************************** | 
|---|
| 36 | BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw) | 
|---|
| 37 | { | 
|---|
| 38 | if(hwndParent == OSLIB_HWND_DESKTOP) | 
|---|
| 39 | { | 
|---|
| 40 | hwndParent = HWND_DESKTOP; | 
|---|
| 41 | } | 
|---|
| 42 | else | 
|---|
| 43 | if(hwndParent == OSLIB_HWND_OBJECT) { | 
|---|
| 44 | hwndParent = HWND_OBJECT; | 
|---|
| 45 | } | 
|---|
| 46 | return (WinSetParent(hwnd, hwndParent, fRedraw) == 0); | 
|---|
| 47 | } | 
|---|
| 48 | //****************************************************************************** | 
|---|
| 49 | //****************************************************************************** | 
|---|
| 50 | BOOL OSLibWinSetOwner(HWND hwnd, HWND hwndOwner) | 
|---|
| 51 | { | 
|---|
| 52 | return WinSetOwner(hwnd, hwndOwner); | 
|---|
| 53 | } | 
|---|
| 54 | //****************************************************************************** | 
|---|
| 55 | //****************************************************************************** | 
|---|
| 56 | HWND OSLibWinCreateWindow(HWND hwndParent,ULONG dwWinStyle, ULONG dwOSFrameStyle, | 
|---|
| 57 | char *pszName, HWND Owner, ULONG fHWND_BOTTOM, | 
|---|
| 58 | ULONG id, BOOL fTaskList,BOOL fShellPosition, | 
|---|
| 59 | int classStyle, HWND *hwndFrame) | 
|---|
| 60 | { | 
|---|
| 61 | HWND  hwndClient; | 
|---|
| 62 | ULONG dwFrameStyle = 0; | 
|---|
| 63 |  | 
|---|
| 64 | if(pszName && *pszName == 0) { | 
|---|
| 65 | pszName = NULL; | 
|---|
| 66 | } | 
|---|
| 67 | if(hwndParent == OSLIB_HWND_DESKTOP) { | 
|---|
| 68 | hwndParent = HWND_DESKTOP; | 
|---|
| 69 | } | 
|---|
| 70 | if(Owner == OSLIB_HWND_DESKTOP) { | 
|---|
| 71 | Owner = HWND_DESKTOP; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | if(classStyle & CS_SAVEBITS_W) dwWinStyle |= WS_SAVEBITS; | 
|---|
| 75 | if(classStyle & CS_PARENTDC_W) dwWinStyle |= WS_PARENTCLIP; | 
|---|
| 76 |  | 
|---|
| 77 | dwWinStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP); | 
|---|
| 78 |  | 
|---|
| 79 | if(fTaskList) | 
|---|
| 80 | { | 
|---|
| 81 | dwFrameStyle |= FCF_NOMOVEWITHOWNER; | 
|---|
| 82 | } | 
|---|
| 83 | if (fShellPosition) dwFrameStyle |= FCF_SHELLPOSITION; | 
|---|
| 84 |  | 
|---|
| 85 | FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0}; | 
|---|
| 86 | FCData.flCreateFlags = dwFrameStyle; | 
|---|
| 87 |  | 
|---|
| 88 | dprintf(("WinCreateWindow %x %s %x task %d shell %d classstyle %x winstyle %x bottom %d", hwndParent, pszName, id, fTaskList, fShellPosition, classStyle, dwWinStyle, fHWND_BOTTOM)); | 
|---|
| 89 |  | 
|---|
| 90 | //Must not use WS_CLIPCHILDREN style with frame window. Transparency won't work otherwise. | 
|---|
| 91 | //Eg: dialog parent, groupbox; invalidate part of groupbox -> painting algorithm stops when it finds | 
|---|
| 92 | //    a window with WS_CLIPCHILDREN -> result: dialog window won't update groupbox background as groupbox only draws the border | 
|---|
| 93 | *hwndFrame = WinCreateWindow(hwndParent, | 
|---|
| 94 | WIN32_STDFRAMECLASS, | 
|---|
| 95 | pszName, (dwWinStyle & ~WS_CLIPCHILDREN), 0, 0, 0, 0, | 
|---|
| 96 | Owner, (fHWND_BOTTOM) ? HWND_BOTTOM : HWND_TOP, | 
|---|
| 97 | id, (PVOID)&FCData, NULL); | 
|---|
| 98 | if(fOS2Look && *hwndFrame) { | 
|---|
| 99 | FCData.flCreateFlags = dwOSFrameStyle; | 
|---|
| 100 | //        FCData.flCreateFlags = FCF_TITLEBAR|FCF_SYSMENU|FCF_MINMAX; | 
|---|
| 101 | WinCreateFrameControls(*hwndFrame, &FCData, NULL); | 
|---|
| 102 | } | 
|---|
| 103 | hwndClient = WinCreateWindow (*hwndFrame, WIN32_STDCLASS, | 
|---|
| 104 | NULL, dwWinStyle | WS_VISIBLE, 0, 0, 0, 0, | 
|---|
| 105 | *hwndFrame, HWND_TOP, FID_CLIENT, NULL, NULL); | 
|---|
| 106 |  | 
|---|
| 107 | return hwndClient; | 
|---|
| 108 | } | 
|---|
| 109 | //****************************************************************************** | 
|---|
| 110 | //Note: Also check OSLibSetWindowStyle when changing this!! | 
|---|
| 111 | //****************************************************************************** | 
|---|
| 112 | BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle) | 
|---|
| 113 | { | 
|---|
| 114 | *OSWinStyle   = 0; | 
|---|
| 115 | *OSFrameStyle = 0; | 
|---|
| 116 |  | 
|---|
| 117 | /* Window styles */ | 
|---|
| 118 | if(dwStyle & WS_DISABLED_W) | 
|---|
| 119 | *OSWinStyle |= WS_DISABLED; | 
|---|
| 120 | if(dwStyle & WS_CLIPSIBLINGS_W) | 
|---|
| 121 | *OSWinStyle |= WS_CLIPSIBLINGS; | 
|---|
| 122 | if(dwStyle & WS_CLIPCHILDREN_W) | 
|---|
| 123 | *OSWinStyle |= WS_CLIPCHILDREN; | 
|---|
| 124 |  | 
|---|
| 125 | if(fOS2Look) { | 
|---|
| 126 | if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) { | 
|---|
| 127 | *OSFrameStyle = FCF_TITLEBAR; | 
|---|
| 128 | if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W)) | 
|---|
| 129 | { | 
|---|
| 130 | *OSFrameStyle |= FCF_SYSMENU; | 
|---|
| 131 | } | 
|---|
| 132 | if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) { | 
|---|
| 133 | *OSFrameStyle |= FCF_MINMAX; | 
|---|
| 134 | } | 
|---|
| 135 | else | 
|---|
| 136 | if(dwStyle & WS_SYSMENU_W) { | 
|---|
| 137 | *OSFrameStyle |= FCF_CLOSEBUTTON; | 
|---|
| 138 | } | 
|---|
| 139 | } | 
|---|
| 140 | } | 
|---|
| 141 | return TRUE; | 
|---|
| 142 | } | 
|---|
| 143 | //****************************************************************************** | 
|---|
| 144 | //****************************************************************************** | 
|---|
| 145 | BOOL OSLibWinPositionFrameControls(HWND hwndFrame, RECTLOS2 *pRect, DWORD dwStyle, | 
|---|
| 146 | DWORD dwExStyle, HICON hSysMenuIcon) | 
|---|
| 147 | { | 
|---|
| 148 | SWP  swp[3]; | 
|---|
| 149 | HWND hwndControl; | 
|---|
| 150 | int  i = 0; | 
|---|
| 151 | static int minmaxwidth  = 0; | 
|---|
| 152 | static int minmaxheight = 0; | 
|---|
| 153 |  | 
|---|
| 154 | if(minmaxwidth == 0) { | 
|---|
| 155 | minmaxwidth  = WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON); | 
|---|
| 156 | minmaxheight = WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON); | 
|---|
| 157 | } | 
|---|
| 158 |  | 
|---|
| 159 | if(fOS2Look == OS2_APPEARANCE_SYSMENU) { | 
|---|
| 160 | hwndControl = WinWindowFromID(hwndFrame, FID_SYSMENU); | 
|---|
| 161 | if(hwndControl) { | 
|---|
| 162 | swp[i].hwnd = hwndControl; | 
|---|
| 163 | swp[i].hwndInsertBehind = HWND_TOP; | 
|---|
| 164 | swp[i].x  = pRect->xLeft; | 
|---|
| 165 | swp[i].y  = pRect->yBottom; | 
|---|
| 166 | if(pRect->yTop - pRect->yBottom > minmaxheight) { | 
|---|
| 167 | swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight; | 
|---|
| 168 | } | 
|---|
| 169 | swp[i].cx = minmaxwidth/2; | 
|---|
| 170 | swp[i].cy = minmaxheight;; | 
|---|
| 171 | swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW; | 
|---|
| 172 | dprintf(("FID_SYSMENU (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy)); | 
|---|
| 173 | pRect->xLeft += minmaxwidth/2; | 
|---|
| 174 | i++; | 
|---|
| 175 | } | 
|---|
| 176 | } | 
|---|
| 177 | else | 
|---|
| 178 | if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W) && hSysMenuIcon) { | 
|---|
| 179 | pRect->xLeft += minmaxwidth/2; | 
|---|
| 180 | } | 
|---|
| 181 |  | 
|---|
| 182 | if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) { | 
|---|
| 183 | hwndControl = WinWindowFromID(hwndFrame, FID_TITLEBAR); | 
|---|
| 184 | if(hwndControl) { | 
|---|
| 185 | swp[i].hwnd = hwndControl; | 
|---|
| 186 | swp[i].hwndInsertBehind = HWND_TOP; | 
|---|
| 187 | swp[i].x  = pRect->xLeft; | 
|---|
| 188 | swp[i].y  = pRect->yBottom; | 
|---|
| 189 | if(pRect->yTop - pRect->yBottom > minmaxheight) { | 
|---|
| 190 | swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight; | 
|---|
| 191 | } | 
|---|
| 192 | swp[i].cx = pRect->xRight - pRect->xLeft; | 
|---|
| 193 | if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) { | 
|---|
| 194 | swp[i].cx -= minmaxwidth; | 
|---|
| 195 | } | 
|---|
| 196 | //there is no close button in warp 3 | 
|---|
| 197 | if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3) { | 
|---|
| 198 | swp[i].cx -= minmaxwidth/2; | 
|---|
| 199 | } | 
|---|
| 200 | swp[i].cy = minmaxheight; | 
|---|
| 201 | swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW; | 
|---|
| 202 | dprintf(("FID_TITLEBAR (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy)); | 
|---|
| 203 | pRect->xLeft += swp[i].cx; | 
|---|
| 204 | i++; | 
|---|
| 205 | } | 
|---|
| 206 | else return FALSE; //no titlebar -> no frame controls | 
|---|
| 207 | } | 
|---|
| 208 | if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W) || (dwStyle & WS_SYSMENU_W)) { | 
|---|
| 209 | hwndControl = WinWindowFromID(hwndFrame, FID_MINMAX); | 
|---|
| 210 | if(hwndControl) { | 
|---|
| 211 | swp[i].hwnd = hwndControl; | 
|---|
| 212 | swp[i].hwndInsertBehind = HWND_TOP; | 
|---|
| 213 | swp[i].x  = pRect->xLeft; | 
|---|
| 214 | swp[i].y  = pRect->yBottom; | 
|---|
| 215 | if(pRect->yTop - pRect->yBottom > minmaxheight) { | 
|---|
| 216 | swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight; | 
|---|
| 217 | } | 
|---|
| 218 | swp[i].cx = 0; | 
|---|
| 219 | if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) { | 
|---|
| 220 | swp[i].cx += minmaxwidth; | 
|---|
| 221 | } | 
|---|
| 222 | //there is no close button in warp 3 | 
|---|
| 223 | if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3) { | 
|---|
| 224 | swp[i].cx += minmaxwidth/2; | 
|---|
| 225 | } | 
|---|
| 226 | swp[i].cy = minmaxheight; | 
|---|
| 227 | swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW; | 
|---|
| 228 | dprintf(("FID_MINMAX (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy)); | 
|---|
| 229 | pRect->xLeft += swp[i].cx; | 
|---|
| 230 | i++; | 
|---|
| 231 | } | 
|---|
| 232 | } | 
|---|
| 233 | return WinSetMultWindowPos(GetThreadHAB(), swp, i); | 
|---|
| 234 | } | 
|---|
| 235 | //****************************************************************************** | 
|---|
| 236 | //****************************************************************************** | 
|---|
| 237 | BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value) | 
|---|
| 238 | { | 
|---|
| 239 | if(offset == OSLIB_QWL_USER) | 
|---|
| 240 | offset = QWL_USER; | 
|---|
| 241 |  | 
|---|
| 242 | return WinSetWindowULong(hwnd, offset, value); | 
|---|
| 243 | } | 
|---|
| 244 | //****************************************************************************** | 
|---|
| 245 | //****************************************************************************** | 
|---|
| 246 | ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset) | 
|---|
| 247 | { | 
|---|
| 248 | if(offset == OSLIB_QWL_USER) | 
|---|
| 249 | offset = QWL_USER; | 
|---|
| 250 |  | 
|---|
| 251 | return WinQueryWindowULong(hwnd, offset); | 
|---|
| 252 | } | 
|---|
| 253 | //****************************************************************************** | 
|---|
| 254 | //****************************************************************************** | 
|---|
| 255 | BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle) | 
|---|
| 256 | { | 
|---|
| 257 | return WinAlarm(hwndDeskTop,flStyle); | 
|---|
| 258 | } | 
|---|
| 259 | //****************************************************************************** | 
|---|
| 260 | HWND OSLibWinQueryFocus(HWND hwndDeskTop) | 
|---|
| 261 | { | 
|---|
| 262 | return WinQueryFocus(hwndDeskTop); | 
|---|
| 263 | } | 
|---|
| 264 | //****************************************************************************** | 
|---|
| 265 | //****************************************************************************** | 
|---|
| 266 | HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id) | 
|---|
| 267 | { | 
|---|
| 268 | return WinWindowFromID(hwndParent,id); | 
|---|
| 269 | } | 
|---|
| 270 | //****************************************************************************** | 
|---|
| 271 | //****************************************************************************** | 
|---|
| 272 | BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate) | 
|---|
| 273 | { | 
|---|
| 274 | return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? 0 : FC_NOSETACTIVE); | 
|---|
| 275 | } | 
|---|
| 276 | //****************************************************************************** | 
|---|
| 277 | //****************************************************************************** | 
|---|
| 278 | BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf) | 
|---|
| 279 | { | 
|---|
| 280 | return WinIsChild (hwnd, hwndOf); | 
|---|
| 281 | } | 
|---|
| 282 | //****************************************************************************** | 
|---|
| 283 | //****************************************************************************** | 
|---|
| 284 | ULONG OSLibGetWindowHeight(HWND hwnd) | 
|---|
| 285 | { | 
|---|
| 286 | RECTL rect; | 
|---|
| 287 |  | 
|---|
| 288 | return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0; | 
|---|
| 289 | } | 
|---|
| 290 | //****************************************************************************** | 
|---|
| 291 | //****************************************************************************** | 
|---|
| 292 | LONG OSLibWinQuerySysValue(LONG iSysValue) | 
|---|
| 293 | { | 
|---|
| 294 | return WinQuerySysValue(HWND_DESKTOP,iSysValue); | 
|---|
| 295 | } | 
|---|
| 296 | //****************************************************************************** | 
|---|
| 297 | //****************************************************************************** | 
|---|
| 298 | BOOL OSLibWinSetSysValue(LONG iSysValue, ULONG val) | 
|---|
| 299 | { | 
|---|
| 300 | return WinQuerySysValue(iSysValue, val); | 
|---|
| 301 | } | 
|---|
| 302 | //****************************************************************************** | 
|---|
| 303 | //****************************************************************************** | 
|---|
| 304 | ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer) | 
|---|
| 305 | { | 
|---|
| 306 | return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer); | 
|---|
| 307 | } | 
|---|
| 308 | //****************************************************************************** | 
|---|
| 309 | //****************************************************************************** | 
|---|
| 310 | BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText) | 
|---|
| 311 | { | 
|---|
| 312 | return WinSetDlgItemText(hwndDlg,idItem,pszText); | 
|---|
| 313 | } | 
|---|
| 314 | //****************************************************************************** | 
|---|
| 315 | //****************************************************************************** | 
|---|
| 316 | BOOL OSLibWinQueryPointerPos(PPOINT pptlPoint) | 
|---|
| 317 | { | 
|---|
| 318 | return WinQueryPointerPos(HWND_DESKTOP,(PPOINTL)pptlPoint); | 
|---|
| 319 | } | 
|---|
| 320 | //****************************************************************************** | 
|---|
| 321 | //****************************************************************************** | 
|---|
| 322 | BOOL OSLibWinSetPointerPos(int x, int y) | 
|---|
| 323 | { | 
|---|
| 324 | return WinSetPointerPos(HWND_DESKTOP, x, y); | 
|---|
| 325 | } | 
|---|
| 326 | //****************************************************************************** | 
|---|
| 327 | //****************************************************************************** | 
|---|
| 328 | HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode) | 
|---|
| 329 | { | 
|---|
| 330 | return WinQueryWindow(hwnd, lCode); | 
|---|
| 331 | } | 
|---|
| 332 | //****************************************************************************** | 
|---|
| 333 | //****************************************************************************** | 
|---|
| 334 | BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num) | 
|---|
| 335 | { | 
|---|
| 336 | return WinSetMultWindowPos(GetThreadHAB(), pswp, num); | 
|---|
| 337 | } | 
|---|
| 338 | //****************************************************************************** | 
|---|
| 339 | //****************************************************************************** | 
|---|
| 340 | BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl) | 
|---|
| 341 | { | 
|---|
| 342 | BOOL rc = 1; | 
|---|
| 343 |  | 
|---|
| 344 | if(fl & SWP_SHOW) { | 
|---|
| 345 | rc = WinShowWindow(hwnd, TRUE); | 
|---|
| 346 | } | 
|---|
| 347 | if(rc == 0) | 
|---|
| 348 | dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB()))); | 
|---|
| 349 | rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, fl); | 
|---|
| 350 | if(rc == 0) | 
|---|
| 351 | dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB()))); | 
|---|
| 352 | return rc; | 
|---|
| 353 | } | 
|---|
| 354 | //****************************************************************************** | 
|---|
| 355 | //****************************************************************************** | 
|---|
| 356 | BOOL OSLibWinDestroyWindow(HWND hwnd) | 
|---|
| 357 | { | 
|---|
| 358 | return WinDestroyWindow(hwnd); | 
|---|
| 359 | } | 
|---|
| 360 | //****************************************************************************** | 
|---|
| 361 | //****************************************************************************** | 
|---|
| 362 | #if 0 | 
|---|
| 363 | BOOL OSLibWinQueryWindowRect(Win32BaseWindow *window, PRECT pRect, int RelativeTo) | 
|---|
| 364 | { | 
|---|
| 365 | BOOL     rc; | 
|---|
| 366 | RECTLOS2 rectl; | 
|---|
| 367 |  | 
|---|
| 368 | rc = WinQueryWindowRect(window->getOS2WindowHandle(), (PRECTL)&rectl); | 
|---|
| 369 | if(rc) { | 
|---|
| 370 | if(RelativeTo == RELATIVE_TO_SCREEN) { | 
|---|
| 371 | mapOS2ToWin32RectFrame(window,windowDesktop,&rectl,pRect); | 
|---|
| 372 | } | 
|---|
| 373 | else    mapOS2ToWin32RectFrame(window,&rectl,pRect); | 
|---|
| 374 | } | 
|---|
| 375 | else  memset(pRect, 0, sizeof(RECT)); | 
|---|
| 376 | return rc; | 
|---|
| 377 | } | 
|---|
| 378 | #endif | 
|---|
| 379 | //****************************************************************************** | 
|---|
| 380 | //****************************************************************************** | 
|---|
| 381 | BOOL OSLibWinIsIconic(HWND hwnd) | 
|---|
| 382 | { | 
|---|
| 383 | SWP  swp; | 
|---|
| 384 | BOOL rc; | 
|---|
| 385 |  | 
|---|
| 386 | rc = WinQueryWindowPos(hwnd, &swp); | 
|---|
| 387 | if(rc == FALSE) { | 
|---|
| 388 | dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd)); | 
|---|
| 389 | return FALSE; | 
|---|
| 390 | } | 
|---|
| 391 |  | 
|---|
| 392 | if(swp.fl & SWP_MINIMIZE) | 
|---|
| 393 | return TRUE; | 
|---|
| 394 | else  return FALSE; | 
|---|
| 395 | } | 
|---|
| 396 | //****************************************************************************** | 
|---|
| 397 | //****************************************************************************** | 
|---|
| 398 | BOOL OSLibWinSetActiveWindow(HWND hwnd) | 
|---|
| 399 | { | 
|---|
| 400 | BOOL rc; | 
|---|
| 401 |  | 
|---|
| 402 | rc = WinSetActiveWindow(HWND_DESKTOP, hwnd); | 
|---|
| 403 | if(rc == FALSE) { | 
|---|
| 404 | dprintf(("WinSetActiveWindow %x failure: %x", hwnd, OSLibWinGetLastError())); | 
|---|
| 405 | } | 
|---|
| 406 | return rc; | 
|---|
| 407 | } | 
|---|
| 408 | //****************************************************************************** | 
|---|
| 409 | //****************************************************************************** | 
|---|
| 410 | BOOL OSLibWinSetFocus(HWND hwnd) | 
|---|
| 411 | { | 
|---|
| 412 | return WinSetFocus(HWND_DESKTOP, hwnd); | 
|---|
| 413 | } | 
|---|
| 414 | //****************************************************************************** | 
|---|
| 415 | //****************************************************************************** | 
|---|
| 416 | BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable) | 
|---|
| 417 | { | 
|---|
| 418 | BOOL rc; | 
|---|
| 419 | HWND hwndClient; | 
|---|
| 420 |  | 
|---|
| 421 | rc = WinEnableWindow(hwnd, fEnable); | 
|---|
| 422 | hwndClient = WinWindowFromID(hwnd, FID_CLIENT); | 
|---|
| 423 | if(hwndClient) { | 
|---|
| 424 | WinEnableWindow(hwndClient, fEnable); | 
|---|
| 425 | } | 
|---|
| 426 | return rc; | 
|---|
| 427 | } | 
|---|
| 428 | //****************************************************************************** | 
|---|
| 429 | //****************************************************************************** | 
|---|
| 430 | BOOL OSLibWinIsWindowEnabled(HWND hwnd) | 
|---|
| 431 | { | 
|---|
| 432 | return WinIsWindowEnabled(hwnd); | 
|---|
| 433 | } | 
|---|
| 434 | //****************************************************************************** | 
|---|
| 435 | //****************************************************************************** | 
|---|
| 436 | BOOL OSLibWinIsWindowVisible(HWND hwnd) | 
|---|
| 437 | { | 
|---|
| 438 | return WinIsWindowVisible(hwnd); | 
|---|
| 439 | } | 
|---|
| 440 | //****************************************************************************** | 
|---|
| 441 | //****************************************************************************** | 
|---|
| 442 | HWND OSLibWinQueryActiveWindow() | 
|---|
| 443 | { | 
|---|
| 444 | return WinQueryActiveWindow(HWND_DESKTOP); | 
|---|
| 445 | } | 
|---|
| 446 | //****************************************************************************** | 
|---|
| 447 | //****************************************************************************** | 
|---|
| 448 | LONG OSLibWinQueryWindowTextLength(HWND hwnd) | 
|---|
| 449 | { | 
|---|
| 450 | return WinQueryWindowTextLength(hwnd); | 
|---|
| 451 | } | 
|---|
| 452 | //****************************************************************************** | 
|---|
| 453 | //****************************************************************************** | 
|---|
| 454 | LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz) | 
|---|
| 455 | { | 
|---|
| 456 | return WinQueryWindowText(hwnd, length, lpsz); | 
|---|
| 457 | } | 
|---|
| 458 | //****************************************************************************** | 
|---|
| 459 | //****************************************************************************** | 
|---|
| 460 | BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz) | 
|---|
| 461 | { | 
|---|
| 462 | return WinSetWindowText(hwnd, lpsz); | 
|---|
| 463 | } | 
|---|
| 464 | //****************************************************************************** | 
|---|
| 465 | //****************************************************************************** | 
|---|
| 466 | BOOL OSLibWinSetTitleBarText(HWND hwnd, LPSTR lpsz) | 
|---|
| 467 | { | 
|---|
| 468 | return WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), lpsz); | 
|---|
| 469 | } | 
|---|
| 470 | //****************************************************************************** | 
|---|
| 471 | //****************************************************************************** | 
|---|
| 472 | BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash) | 
|---|
| 473 | { | 
|---|
| 474 | return WinFlashWindow(hwnd, fFlash); | 
|---|
| 475 | } | 
|---|
| 476 | //****************************************************************************** | 
|---|
| 477 | //****************************************************************************** | 
|---|
| 478 | HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint) | 
|---|
| 479 | { | 
|---|
| 480 | return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE); | 
|---|
| 481 | } | 
|---|
| 482 | //****************************************************************************** | 
|---|
| 483 | //****************************************************************************** | 
|---|
| 484 | BOOL OSLibWinMinimizeWindow(HWND hwnd) | 
|---|
| 485 | { | 
|---|
| 486 | return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE); | 
|---|
| 487 | } | 
|---|
| 488 | //****************************************************************************** | 
|---|
| 489 | //****************************************************************************** | 
|---|
| 490 | BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl) | 
|---|
| 491 | { | 
|---|
| 492 | pointl->x = 0; | 
|---|
| 493 | pointl->y = 0; | 
|---|
| 494 | return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0); | 
|---|
| 495 | } | 
|---|
| 496 | //****************************************************************************** | 
|---|
| 497 | //****************************************************************************** | 
|---|
| 498 | BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon) | 
|---|
| 499 | { | 
|---|
| 500 | ULONG hIconOS2 = GetOS2Icon(hIcon); | 
|---|
| 501 | if(hIconOS2) | 
|---|
| 502 | return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIconOS2, 0); | 
|---|
| 503 | return FALSE; | 
|---|
| 504 | } | 
|---|
| 505 | //****************************************************************************** | 
|---|
| 506 | //****************************************************************************** | 
|---|
| 507 | BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp) | 
|---|
| 508 | { | 
|---|
| 509 | return WinQueryWindowPos(hwnd, pswp); | 
|---|
| 510 | } | 
|---|
| 511 | //****************************************************************************** | 
|---|
| 512 | //****************************************************************************** | 
|---|
| 513 | void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld, | 
|---|
| 514 | int parentHeight, HWND hwnd) | 
|---|
| 515 | { | 
|---|
| 516 | HWND hWindow            = pswp->hwnd; | 
|---|
| 517 | HWND hWndInsertAfter    = pswp->hwndInsertBehind; | 
|---|
| 518 | long x                  = pswp->x; | 
|---|
| 519 | long y                  = pswp->y; | 
|---|
| 520 | long cx                 = pswp->cx; | 
|---|
| 521 | long cy                 = pswp->cy; | 
|---|
| 522 | UINT fuFlags            = (UINT)pswp->fl; | 
|---|
| 523 |  | 
|---|
| 524 | HWND   hWinAfter; | 
|---|
| 525 | ULONG  flags = 0; | 
|---|
| 526 |  | 
|---|
| 527 | HWND  hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow; | 
|---|
| 528 |  | 
|---|
| 529 | if (hWndInsertAfter == HWND_TOP) | 
|---|
| 530 | hWinAfter = HWND_TOP_W; | 
|---|
| 531 | else if (hWndInsertAfter == HWND_BOTTOM) | 
|---|
| 532 | hWinAfter = HWND_BOTTOM_W; | 
|---|
| 533 | else | 
|---|
| 534 | hWinAfter = (HWND) hWndInsertAfter; | 
|---|
| 535 |  | 
|---|
| 536 | //*********************************** | 
|---|
| 537 | // convert PM flags to Windows flags | 
|---|
| 538 | //*********************************** | 
|---|
| 539 | if (!(fuFlags & SWP_SIZE))       flags |= SWP_NOSIZE_W; | 
|---|
| 540 | if (!(fuFlags & SWP_MOVE))       flags |= SWP_NOMOVE_W; | 
|---|
| 541 | if (!(fuFlags & SWP_ZORDER))     flags |= SWP_NOZORDER_W; | 
|---|
| 542 | if (  fuFlags & SWP_NOREDRAW)    flags |= SWP_NOREDRAW_W; | 
|---|
| 543 | if (!(fuFlags & SWP_ACTIVATE))   flags |= SWP_NOACTIVATE_W; | 
|---|
| 544 | if (  fuFlags & SWP_SHOW)        flags |= SWP_SHOWWINDOW_W; | 
|---|
| 545 | if (  fuFlags & SWP_HIDE)        flags |= SWP_HIDEWINDOW_W; | 
|---|
| 546 | if (  fuFlags & SWP_NOADJUST)    flags |= SWP_NOSENDCHANGING_W; | 
|---|
| 547 |  | 
|---|
| 548 | if(fuFlags & (SWP_MOVE | SWP_SIZE)) | 
|---|
| 549 | { | 
|---|
| 550 | y  = parentHeight - y - pswp->cy; | 
|---|
| 551 |  | 
|---|
| 552 | if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y)) | 
|---|
| 553 | flags |= SWP_NOMOVE_W; | 
|---|
| 554 |  | 
|---|
| 555 | if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy)) | 
|---|
| 556 | flags |= SWP_NOSIZE_W; | 
|---|
| 557 |  | 
|---|
| 558 | if (fuFlags & SWP_SIZE) | 
|---|
| 559 | { | 
|---|
| 560 | if (pswp->cy != pswpOld->cy) | 
|---|
| 561 | { | 
|---|
| 562 | flags &= ~SWP_NOMOVE_W; | 
|---|
| 563 | } | 
|---|
| 564 | } | 
|---|
| 565 | } | 
|---|
| 566 |  | 
|---|
| 567 | pswpOld->x  = pswp->x; | 
|---|
| 568 | pswpOld->y  = parentHeight-pswp->y-pswp->cy; | 
|---|
| 569 | pswpOld->cx = pswp->cx; | 
|---|
| 570 | pswpOld->cy = pswp->cy; | 
|---|
| 571 |  | 
|---|
| 572 | dprintf(("window (%d,%d)(%d,%d)  client (%d,%d)(%d,%d)", | 
|---|
| 573 | x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy)); | 
|---|
| 574 |  | 
|---|
| 575 | pwpos->flags            = (UINT)flags; | 
|---|
| 576 | pwpos->cy               = cy; | 
|---|
| 577 | pwpos->cx               = cx; | 
|---|
| 578 | pwpos->x                = x; | 
|---|
| 579 | pwpos->y                = y; | 
|---|
| 580 | pwpos->hwndInsertAfter  = hWinAfter; | 
|---|
| 581 | pwpos->hwnd             = hWindow; | 
|---|
| 582 | } | 
|---|
| 583 | //****************************************************************************** | 
|---|
| 584 | //****************************************************************************** | 
|---|
| 585 | void OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld, | 
|---|
| 586 | int parentHeight, HWND hFrame) | 
|---|
| 587 | { | 
|---|
| 588 | BOOL fCvt = FALSE; | 
|---|
| 589 |  | 
|---|
| 590 | HWND hWnd            = pwpos->hwnd; | 
|---|
| 591 | HWND hWndInsertAfter = pwpos->hwndInsertAfter; | 
|---|
| 592 | long x               = pwpos->x; | 
|---|
| 593 | long y               = pwpos->y; | 
|---|
| 594 | long cx              = pwpos->cx; | 
|---|
| 595 | long cy              = pwpos->cy; | 
|---|
| 596 | UINT fuFlags         = pwpos->flags; | 
|---|
| 597 |  | 
|---|
| 598 | HWND  hWinAfter; | 
|---|
| 599 | ULONG flags = 0; | 
|---|
| 600 | HWND  hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP; | 
|---|
| 601 |  | 
|---|
| 602 | if (hWndInsertAfter == HWND_TOPMOST_W) | 
|---|
| 603 | //      hWinAfter = HWND_TOPMOST; | 
|---|
| 604 | hWinAfter = HWND_TOP; | 
|---|
| 605 | else if (hWndInsertAfter == HWND_NOTOPMOST_W) | 
|---|
| 606 | //      hWinAfter = HWND_NOTOPMOST; | 
|---|
| 607 | hWinAfter = HWND_TOP; | 
|---|
| 608 | else if (hWndInsertAfter == HWND_TOP_W) | 
|---|
| 609 | hWinAfter = HWND_TOP; | 
|---|
| 610 | else if (hWndInsertAfter == HWND_BOTTOM_W) | 
|---|
| 611 | hWinAfter = HWND_BOTTOM; | 
|---|
| 612 | else | 
|---|
| 613 | hWinAfter = (HWND) hWndInsertAfter; | 
|---|
| 614 |  | 
|---|
| 615 | if (!(fuFlags & SWP_NOSIZE_W    )) flags |= SWP_SIZE; | 
|---|
| 616 | if (!(fuFlags & SWP_NOMOVE_W    )) flags |= SWP_MOVE; | 
|---|
| 617 | if (!(fuFlags & SWP_NOZORDER_W  )) flags |= SWP_ZORDER; | 
|---|
| 618 | if (  fuFlags & SWP_NOREDRAW_W  )  flags |= SWP_NOREDRAW; | 
|---|
| 619 | if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE; | 
|---|
| 620 | if (  fuFlags & SWP_SHOWWINDOW_W)  flags |= SWP_SHOW; | 
|---|
| 621 | if (  fuFlags & SWP_HIDEWINDOW_W)  flags |= SWP_HIDE; | 
|---|
| 622 | if (  fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST; | 
|---|
| 623 |  | 
|---|
| 624 | if(flags & (SWP_MOVE | SWP_SIZE)) | 
|---|
| 625 | { | 
|---|
| 626 | if((flags & SWP_MOVE) == 0) | 
|---|
| 627 | { | 
|---|
| 628 | x = pswpOld->x; | 
|---|
| 629 | y = pswpOld->y; | 
|---|
| 630 |  | 
|---|
| 631 | y = parentHeight - y - pswpOld->cy; | 
|---|
| 632 | } | 
|---|
| 633 |  | 
|---|
| 634 | if(flags & SWP_SIZE) | 
|---|
| 635 | { | 
|---|
| 636 | if (cy != pswpOld->cy) | 
|---|
| 637 | flags |= SWP_MOVE; | 
|---|
| 638 | } | 
|---|
| 639 | else | 
|---|
| 640 | { | 
|---|
| 641 | cx = pswpOld->cx; | 
|---|
| 642 | cy = pswpOld->cy; | 
|---|
| 643 | } | 
|---|
| 644 | y = parentHeight - y - cy; | 
|---|
| 645 |  | 
|---|
| 646 | if ((pswpOld->x == x) && (pswpOld->y == y)) | 
|---|
| 647 | flags &= ~SWP_MOVE; | 
|---|
| 648 |  | 
|---|
| 649 | if ((pswpOld->cx == cx) && (pswpOld->cy == cy)) | 
|---|
| 650 | flags &= ~SWP_SIZE; | 
|---|
| 651 | } | 
|---|
| 652 |  | 
|---|
| 653 | pswp->fl               = flags; | 
|---|
| 654 | pswp->cy               = cy; | 
|---|
| 655 | pswp->cx               = cx; | 
|---|
| 656 | pswp->x                = x; | 
|---|
| 657 | pswp->y                = y; | 
|---|
| 658 | pswp->hwndInsertBehind = hWinAfter; | 
|---|
| 659 | pswp->hwnd             = hWindow; | 
|---|
| 660 | pswp->ulReserved1      = 0; | 
|---|
| 661 | pswp->ulReserved2      = 0; | 
|---|
| 662 | } | 
|---|
| 663 | //****************************************************************************** | 
|---|
| 664 | //****************************************************************************** | 
|---|
| 665 | void OSLibWinSetClientPos(HWND hwnd, int x, int y, int cx, int cy, int parentHeight) | 
|---|
| 666 | { | 
|---|
| 667 | SWP swp; | 
|---|
| 668 | BOOL rc; | 
|---|
| 669 |  | 
|---|
| 670 | swp.hwnd = hwnd; | 
|---|
| 671 | swp.hwndInsertBehind = 0; | 
|---|
| 672 | swp.x  = x; | 
|---|
| 673 | swp.y  = parentHeight - y - cy; | 
|---|
| 674 | swp.cx = cx; | 
|---|
| 675 | swp.cy = cy; | 
|---|
| 676 | swp.fl = SWP_MOVE | SWP_SIZE; | 
|---|
| 677 |  | 
|---|
| 678 | dprintf(("OSLibWinSetClientPos (%d,%d) (%d,%d) -> (%d,%d) (%d,%d)", x, y, x+cx, y+cy, swp.x, swp.y, swp.x+swp.cx, swp.y+swp.cy)); | 
|---|
| 679 |  | 
|---|
| 680 | rc = WinSetMultWindowPos(GetThreadHAB(), &swp, 1); | 
|---|
| 681 | if(rc == FALSE) { | 
|---|
| 682 | dprintf(("OSLibWinSetClientPos: WinSetMultWindowPos %x failed %x", hwnd, WinGetLastError(GetThreadHAB()))); | 
|---|
| 683 | } | 
|---|
| 684 | } | 
|---|
| 685 | //****************************************************************************** | 
|---|
| 686 | //****************************************************************************** | 
|---|
| 687 | BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient) | 
|---|
| 688 | { | 
|---|
| 689 | BOOL rc; | 
|---|
| 690 |  | 
|---|
| 691 | WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2); | 
|---|
| 692 |  | 
|---|
| 693 | rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient); | 
|---|
| 694 | WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2); | 
|---|
| 695 |  | 
|---|
| 696 | return rc; | 
|---|
| 697 | } | 
|---|
| 698 | //****************************************************************************** | 
|---|
| 699 | //****************************************************************************** | 
|---|
| 700 | BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax) | 
|---|
| 701 | { | 
|---|
| 702 | TRACKINFO tinfo; | 
|---|
| 703 |  | 
|---|
| 704 | memset(&tinfo, 0, sizeof(TRACKINFO)); | 
|---|
| 705 | WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo); | 
|---|
| 706 |  | 
|---|
| 707 | pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x; | 
|---|
| 708 | pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y; | 
|---|
| 709 | pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x; | 
|---|
| 710 | pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y; | 
|---|
| 711 | return TRUE; | 
|---|
| 712 | } | 
|---|
| 713 | //****************************************************************************** | 
|---|
| 714 | //****************************************************************************** | 
|---|
| 715 | HWND OSLibWinBeginEnumWindows(HWND hwnd) | 
|---|
| 716 | { | 
|---|
| 717 | if(hwnd == OSLIB_HWND_DESKTOP)       hwnd = HWND_DESKTOP; | 
|---|
| 718 | else | 
|---|
| 719 | if(hwnd == OSLIB_HWND_OBJECT)        hwnd = HWND_OBJECT; | 
|---|
| 720 |  | 
|---|
| 721 | return WinBeginEnumWindows(hwnd); | 
|---|
| 722 | } | 
|---|
| 723 | //****************************************************************************** | 
|---|
| 724 | //****************************************************************************** | 
|---|
| 725 | HWND OSLibWinGetNextWindow(HWND hwndEnum) | 
|---|
| 726 | { | 
|---|
| 727 | return WinGetNextWindow(hwndEnum); | 
|---|
| 728 | } | 
|---|
| 729 | //****************************************************************************** | 
|---|
| 730 | //****************************************************************************** | 
|---|
| 731 | HWND OSLibWinQueryClientWindow(HWND hwndFrame) | 
|---|
| 732 | { | 
|---|
| 733 | HWND hwndClient = 0; | 
|---|
| 734 |  | 
|---|
| 735 | if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME) | 
|---|
| 736 | hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT); | 
|---|
| 737 |  | 
|---|
| 738 | return hwndClient; | 
|---|
| 739 | } | 
|---|
| 740 | //****************************************************************************** | 
|---|
| 741 | //****************************************************************************** | 
|---|
| 742 | BOOL OSLibWinEndEnumWindows(HWND hwndEnum) | 
|---|
| 743 | { | 
|---|
| 744 | return WinEndEnumWindows(hwndEnum); | 
|---|
| 745 | } | 
|---|
| 746 | //****************************************************************************** | 
|---|
| 747 | //****************************************************************************** | 
|---|
| 748 | BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid) | 
|---|
| 749 | { | 
|---|
| 750 | return WinQueryWindowProcess(hwnd, pid, tid); | 
|---|
| 751 | } | 
|---|
| 752 | //****************************************************************************** | 
|---|
| 753 | //****************************************************************************** | 
|---|
| 754 | BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num) | 
|---|
| 755 | { | 
|---|
| 756 | return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num); | 
|---|
| 757 | } | 
|---|
| 758 | //****************************************************************************** | 
|---|
| 759 | //****************************************************************************** | 
|---|
| 760 | HWND OSLibWinQueryObjectWindow(VOID) | 
|---|
| 761 | { | 
|---|
| 762 | return WinQueryObjectWindow(HWND_DESKTOP); | 
|---|
| 763 | } | 
|---|
| 764 | //****************************************************************************** | 
|---|
| 765 | //****************************************************************************** | 
|---|
| 766 | HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID) | 
|---|
| 767 | { | 
|---|
| 768 | HWND   hwndNext, hwndFound=0; | 
|---|
| 769 | HENUM  henum; | 
|---|
| 770 |  | 
|---|
| 771 | henum = WinBeginEnumWindows(HWND_OBJECT); | 
|---|
| 772 | while ((hwndNext = WinGetNextWindow(henum)) != 0) | 
|---|
| 773 | { | 
|---|
| 774 | if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner && | 
|---|
| 775 | WinQueryWindowUShort(hwndNext, QWS_ID) == ID) | 
|---|
| 776 | { | 
|---|
| 777 | hwndFound = hwndNext; | 
|---|
| 778 | break; | 
|---|
| 779 | } | 
|---|
| 780 | } | 
|---|
| 781 | WinEndEnumWindows(henum); | 
|---|
| 782 | return hwndFound; | 
|---|
| 783 | } | 
|---|
| 784 | //****************************************************************************** | 
|---|
| 785 | //****************************************************************************** | 
|---|
| 786 | BOOL OSLibSetWindowID(HWND hwnd, ULONG value) | 
|---|
| 787 | { | 
|---|
| 788 | dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value)); | 
|---|
| 789 | return WinSetWindowULong(hwnd, QWS_ID, value); | 
|---|
| 790 | } | 
|---|
| 791 | //****************************************************************************** | 
|---|
| 792 | //****************************************************************************** | 
|---|
| 793 | PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc) | 
|---|
| 794 | { | 
|---|
| 795 | return WinSubclassWindow(hwnd,(PFNWP)newWndProc); | 
|---|
| 796 | } | 
|---|
| 797 | //****************************************************************************** | 
|---|
| 798 | //****************************************************************************** | 
|---|
| 799 | BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect) | 
|---|
| 800 | { | 
|---|
| 801 | ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT)); | 
|---|
| 802 |  | 
|---|
| 803 | WinSetWindowUShort(hwnd, QWS_XRESTORE,  (USHORT)pRect->left ); | 
|---|
| 804 | WinSetWindowUShort(hwnd, QWS_YRESTORE,  (USHORT)(yHeight - pRect->top - | 
|---|
| 805 | (pRect->bottom - pRect->top))); | 
|---|
| 806 | WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left)); | 
|---|
| 807 | WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top)); | 
|---|
| 808 | return TRUE; | 
|---|
| 809 | } | 
|---|
| 810 | //****************************************************************************** | 
|---|
| 811 | //****************************************************************************** | 
|---|
| 812 | BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y) | 
|---|
| 813 | { | 
|---|
| 814 | ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT)); | 
|---|
| 815 |  | 
|---|
| 816 | WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x ); | 
|---|
| 817 | WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y - | 
|---|
| 818 | ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) - | 
|---|
| 819 | WinQuerySysValue( HWND_DESKTOP, SV_CYICON))); | 
|---|
| 820 | return TRUE; | 
|---|
| 821 | } | 
|---|
| 822 | //****************************************************************************** | 
|---|
| 823 | //****************************************************************************** | 
|---|
| 824 | BOOL OSLibWinGetKeyboardStateTable(unsigned char *PMKeyState) | 
|---|
| 825 | { | 
|---|
| 826 | return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, FALSE ); | 
|---|
| 827 | } | 
|---|
| 828 | //****************************************************************************** | 
|---|
| 829 | //****************************************************************************** | 
|---|
| 830 | BOOL OSLibWinSetKeyboardStateTable(unsigned char *PMKeyState) | 
|---|
| 831 | { | 
|---|
| 832 | return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, TRUE ); | 
|---|
| 833 | } | 
|---|
| 834 | //****************************************************************************** | 
|---|
| 835 | //****************************************************************************** | 
|---|
| 836 | USHORT APIENTRY WinTranslateChar2( USHORT  /* Codepage (currently ignored) */ | 
|---|
| 837 | , PUSHORT /* Ptr to char to translate     */ | 
|---|
| 838 | , PULONG  /* Ptr to deadkey save info     */ | 
|---|
| 839 | , USHORT  /* Translation option (TC_xxx)  */ | 
|---|
| 840 | , PUSHORT /* Ptr to shift state (TCF_xxx) */ | 
|---|
| 841 | ); | 
|---|
| 842 | //****************************************************************************** | 
|---|
| 843 | //****************************************************************************** | 
|---|
| 844 | USHORT OSLibWinTranslateChar(USHORT usScanCode, ULONG type, USHORT shiftstate) | 
|---|
| 845 | { | 
|---|
| 846 | WinTranslateChar2(0, &usScanCode, NULL, type, &shiftstate); | 
|---|
| 847 | return usScanCode; | 
|---|
| 848 | } | 
|---|
| 849 | //****************************************************************************** | 
|---|
| 850 | //****************************************************************************** | 
|---|
| 851 | BOOL OSLibWinEnableWindowUpdate(HWND hwndFrame, HWND hwndClient ,BOOL fEnable) | 
|---|
| 852 | { | 
|---|
| 853 | WinEnableWindowUpdate(hwndFrame, fEnable); | 
|---|
| 854 | return WinEnableWindowUpdate(hwndClient, fEnable); | 
|---|
| 855 | } | 
|---|
| 856 | //****************************************************************************** | 
|---|
| 857 | //****************************************************************************** | 
|---|
| 858 | ULONG OSLibWinGetLastError() | 
|---|
| 859 | { | 
|---|
| 860 | return WinGetLastError(GetThreadHAB()) & 0xFFFF; | 
|---|
| 861 | } | 
|---|
| 862 | //****************************************************************************** | 
|---|
| 863 | //****************************************************************************** | 
|---|
| 864 | void OSLibWinShowTaskList(HWND hwndFrame) | 
|---|
| 865 | { | 
|---|
| 866 | //CB: don't know if this works on all machines | 
|---|
| 867 | WinSetActiveWindow(HWND_DESKTOP,0x8000000E); | 
|---|
| 868 | } | 
|---|
| 869 | //****************************************************************************** | 
|---|
| 870 | //****************************************************************************** | 
|---|
| 871 | void OSLibSetWindowStyle(HWND hwndFrame, HWND hwndClient, ULONG dwStyle, ULONG dwExStyle) | 
|---|
| 872 | { | 
|---|
| 873 | ULONG dwWinStyle; | 
|---|
| 874 | ULONG dwOldWinStyle; | 
|---|
| 875 |  | 
|---|
| 876 | //client window: | 
|---|
| 877 | dwWinStyle    = WinQueryWindowULong(hwndClient, QWL_STYLE); | 
|---|
| 878 | dwOldWinStyle = dwWinStyle; | 
|---|
| 879 |  | 
|---|
| 880 | if(dwStyle & WS_CLIPCHILDREN_W) { | 
|---|
| 881 | dwWinStyle |= WS_CLIPCHILDREN; | 
|---|
| 882 | } | 
|---|
| 883 | else dwWinStyle &= ~WS_CLIPCHILDREN; | 
|---|
| 884 |  | 
|---|
| 885 | if(dwWinStyle != dwOldWinStyle) { | 
|---|
| 886 | WinSetWindowULong(hwndClient, QWL_STYLE, dwWinStyle); | 
|---|
| 887 | } | 
|---|
| 888 |  | 
|---|
| 889 | //Frame window | 
|---|
| 890 | dwWinStyle    = WinQueryWindowULong(hwndFrame, QWL_STYLE); | 
|---|
| 891 | dwOldWinStyle = dwWinStyle; | 
|---|
| 892 | if(dwStyle & WS_DISABLED_W) { | 
|---|
| 893 | dwWinStyle |= WS_DISABLED; | 
|---|
| 894 | } | 
|---|
| 895 | else dwWinStyle &= ~WS_DISABLED; | 
|---|
| 896 |  | 
|---|
| 897 | if(dwStyle & WS_CLIPSIBLINGS_W) { | 
|---|
| 898 | dwWinStyle |= WS_CLIPSIBLINGS; | 
|---|
| 899 | } | 
|---|
| 900 | else dwWinStyle &= ~WS_CLIPSIBLINGS; | 
|---|
| 901 |  | 
|---|
| 902 | if(dwStyle & WS_MINIMIZE_W) { | 
|---|
| 903 | dwWinStyle |= WS_MINIMIZED; | 
|---|
| 904 | } | 
|---|
| 905 | else dwWinStyle &= ~WS_MINIMIZED; | 
|---|
| 906 |  | 
|---|
| 907 | if(dwStyle & WS_MAXIMIZE_W) { | 
|---|
| 908 | dwWinStyle |= WS_MAXIMIZED; | 
|---|
| 909 | } | 
|---|
| 910 | else dwWinStyle &= ~WS_MAXIMIZED; | 
|---|
| 911 |  | 
|---|
| 912 | if(dwWinStyle != dwOldWinStyle) { | 
|---|
| 913 | WinSetWindowULong(hwndFrame, QWL_STYLE, dwWinStyle); | 
|---|
| 914 | } | 
|---|
| 915 | if(fOS2Look) { | 
|---|
| 916 | ULONG OSFrameStyle = 0; | 
|---|
| 917 | if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) { | 
|---|
| 918 | if(WinWindowFromID(hwndFrame, FID_TITLEBAR) == 0) { | 
|---|
| 919 | OSFrameStyle = FCF_TITLEBAR; | 
|---|
| 920 | } | 
|---|
| 921 | if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W)) | 
|---|
| 922 | { | 
|---|
| 923 | if(WinWindowFromID(hwndFrame, FID_SYSMENU) == 0) { | 
|---|
| 924 | OSFrameStyle |= FCF_SYSMENU; | 
|---|
| 925 | } | 
|---|
| 926 | } | 
|---|
| 927 | if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) { | 
|---|
| 928 | if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) { | 
|---|
| 929 | OSFrameStyle |= FCF_MINMAX; | 
|---|
| 930 | } | 
|---|
| 931 | } | 
|---|
| 932 | else | 
|---|
| 933 | if(dwStyle & WS_SYSMENU_W) { | 
|---|
| 934 | if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) { | 
|---|
| 935 | OSFrameStyle |= FCF_CLOSEBUTTON; | 
|---|
| 936 | } | 
|---|
| 937 | } | 
|---|
| 938 | } | 
|---|
| 939 | if(OSFrameStyle) { | 
|---|
| 940 | FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0}; | 
|---|
| 941 |  | 
|---|
| 942 | FCData.flCreateFlags = OSFrameStyle; | 
|---|
| 943 | WinCreateFrameControls(hwndFrame, &FCData, NULL); | 
|---|
| 944 | } | 
|---|
| 945 | } | 
|---|
| 946 | } | 
|---|
| 947 | //****************************************************************************** | 
|---|
| 948 | //****************************************************************************** | 
|---|
| 949 | DWORD OSLibQueryWindowStyle(HWND hwnd) | 
|---|
| 950 | { | 
|---|
| 951 | return WinQueryWindowULong(hwnd, QWL_STYLE); | 
|---|
| 952 | } | 
|---|
| 953 | //****************************************************************************** | 
|---|
| 954 | //****************************************************************************** | 
|---|
| 955 | void OSLibWinSetVisibleRegionNotify(HWND hwnd, BOOL fNotify) | 
|---|
| 956 | { | 
|---|
| 957 | WinSetVisibleRegionNotify(hwnd, fNotify); | 
|---|
| 958 | } | 
|---|
| 959 | //****************************************************************************** | 
|---|
| 960 | //****************************************************************************** | 
|---|
| 961 | HWND OSLibWinQueryCapture() | 
|---|
| 962 | { | 
|---|
| 963 | return WinQueryCapture(HWND_DESKTOP); | 
|---|
| 964 | } | 
|---|
| 965 | //****************************************************************************** | 
|---|
| 966 | //****************************************************************************** | 
|---|
| 967 | BOOL OSLibWinSetCapture(HWND hwnd) | 
|---|
| 968 | { | 
|---|
| 969 | return WinSetCapture(HWND_DESKTOP, hwnd); | 
|---|
| 970 | } | 
|---|
| 971 | //****************************************************************************** | 
|---|
| 972 | //****************************************************************************** | 
|---|
| 973 | BOOL OSLibWinRemoveFromTasklist(HANDLE hTaskList) | 
|---|
| 974 | { | 
|---|
| 975 | return (WinRemoveSwitchEntry(hTaskList)) ? FALSE : TRUE; | 
|---|
| 976 | } | 
|---|
| 977 | //****************************************************************************** | 
|---|
| 978 | //****************************************************************************** | 
|---|
| 979 | HANDLE OSLibWinAddToTaskList(HWND hwndFrame, char *title, BOOL fVisible) | 
|---|
| 980 | { | 
|---|
| 981 | SWCNTRL swctrl; | 
|---|
| 982 | ULONG   tid; | 
|---|
| 983 |  | 
|---|
| 984 | swctrl.hwnd          = hwndFrame; | 
|---|
| 985 | swctrl.hwndIcon      = 0; | 
|---|
| 986 | swctrl.hprog         = 0; | 
|---|
| 987 | WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid); | 
|---|
| 988 | swctrl.idSession     = 0; | 
|---|
| 989 | swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE; | 
|---|
| 990 | swctrl.fbJump        = SWL_JUMPABLE; | 
|---|
| 991 | swctrl.bProgType     = PROG_PM; | 
|---|
| 992 | if(title) { | 
|---|
| 993 | strncpy(swctrl.szSwtitle, title, MAXNAMEL+4); | 
|---|
| 994 | swctrl.szSwtitle[MAXNAMEL+4-1] = 0; | 
|---|
| 995 | } | 
|---|
| 996 | else { | 
|---|
| 997 | swctrl.szSwtitle[0] = 0; | 
|---|
| 998 | swctrl.uchVisibility    = SWL_INVISIBLE; | 
|---|
| 999 | } | 
|---|
| 1000 | return WinAddSwitchEntry(&swctrl); | 
|---|
| 1001 | } | 
|---|
| 1002 | //****************************************************************************** | 
|---|
| 1003 | //****************************************************************************** | 
|---|
| 1004 | BOOL OSLibWinChangeTaskList(HANDLE hTaskList, HWND hwndFrame, char *title, BOOL fVisible) | 
|---|
| 1005 | { | 
|---|
| 1006 | SWCNTRL swctrl; | 
|---|
| 1007 | ULONG   tid; | 
|---|
| 1008 |  | 
|---|
| 1009 | swctrl.hwnd          = hwndFrame; | 
|---|
| 1010 | swctrl.hwndIcon      = 0; | 
|---|
| 1011 | swctrl.hprog         = 0; | 
|---|
| 1012 | WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid); | 
|---|
| 1013 | swctrl.idSession     = 0; | 
|---|
| 1014 | swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE; | 
|---|
| 1015 | swctrl.fbJump        = SWL_JUMPABLE; | 
|---|
| 1016 | swctrl.bProgType     = PROG_PM; | 
|---|
| 1017 | if(title) { | 
|---|
| 1018 | strncpy(swctrl.szSwtitle, title, MAXNAMEL+4); | 
|---|
| 1019 | swctrl.szSwtitle[MAXNAMEL+4-1] = 0; | 
|---|
| 1020 | } | 
|---|
| 1021 | else { | 
|---|
| 1022 | swctrl.szSwtitle[0] = 0; | 
|---|
| 1023 | swctrl.uchVisibility    = SWL_INVISIBLE; | 
|---|
| 1024 | } | 
|---|
| 1025 | return (WinChangeSwitchEntry(hTaskList, &swctrl)) ? FALSE : TRUE; | 
|---|
| 1026 | } | 
|---|
| 1027 | //****************************************************************************** | 
|---|
| 1028 | //****************************************************************************** | 
|---|
| 1029 | BOOL OSLibWinLockWindowUpdate(HWND hwnd) | 
|---|
| 1030 | { | 
|---|
| 1031 | return WinLockWindowUpdate(HWND_DESKTOP, (HWND)hwnd); | 
|---|
| 1032 | } | 
|---|
| 1033 | //****************************************************************************** | 
|---|
| 1034 | //****************************************************************************** | 
|---|
| 1035 | ULONG OSLibGetScreenHeight() | 
|---|
| 1036 | { | 
|---|
| 1037 | return ScreenHeight; | 
|---|
| 1038 | } | 
|---|
| 1039 | //****************************************************************************** | 
|---|
| 1040 | //****************************************************************************** | 
|---|
| 1041 | ULONG OSLibGetScreenWidth() | 
|---|
| 1042 | { | 
|---|
| 1043 | return ScreenWidth; | 
|---|
| 1044 | } | 
|---|
| 1045 | //****************************************************************************** | 
|---|
| 1046 | //Returns the maximum position for a window | 
|---|
| 1047 | //Should only be used from toplevel windows | 
|---|
| 1048 | //****************************************************************************** | 
|---|
| 1049 | BOOL OSLibWinGetMaxPosition(HWND hwndOS2, RECT *rect) | 
|---|
| 1050 | { | 
|---|
| 1051 | SWP  swp; | 
|---|
| 1052 |  | 
|---|
| 1053 | if(!WinGetMaxPosition(hwndOS2, &swp)) { | 
|---|
| 1054 | dprintf(("WARNING: WinGetMaxPosition %x returned FALSE", hwndOS2)); | 
|---|
| 1055 | return FALSE; | 
|---|
| 1056 | } | 
|---|
| 1057 | rect->left   = swp.x; | 
|---|
| 1058 | rect->right  = swp.x + swp.cx; | 
|---|
| 1059 | rect->top    = ScreenHeight - (swp.y + swp.cy); | 
|---|
| 1060 | rect->bottom = ScreenHeight - swp.y; | 
|---|
| 1061 | return TRUE; | 
|---|
| 1062 | } | 
|---|
| 1063 | //****************************************************************************** | 
|---|
| 1064 | //****************************************************************************** | 
|---|
| 1065 | BOOL OSLibWinShowPointer(BOOL fShow) | 
|---|
| 1066 | { | 
|---|
| 1067 | return WinShowPointer(HWND_DESKTOP, fShow); | 
|---|
| 1068 | } | 
|---|
| 1069 | //****************************************************************************** | 
|---|
| 1070 | //****************************************************************************** | 
|---|