00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #define INCL_WIN
00014 #define INCL_PM
00015 #define INCL_WINSWITCHLIST
00016 #include <os2wrap.h>
00017 #include <stdlib.h>
00018 #include <string.h>
00019
00020 #include <misc.h>
00021 #include <win32type.h>
00022 #include <winconst.h>
00023 #include <winuser32.h>
00024 #include "oslibwin.h"
00025 #include "oslibutil.h"
00026 #include "oslibmsg.h"
00027 #include "oslibgdi.h"
00028 #include "pmwindow.h"
00029 #include "initterm.h"
00030
00031 #define DBG_LOCALLOG DBG_oslibwin
00032 #include "dbglocal.h"
00033
00034
00035
00036 BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
00037 {
00038 if(hwndParent == OSLIB_HWND_DESKTOP)
00039 {
00040 hwndParent = HWND_DESKTOP;
00041 }
00042 else
00043 if(hwndParent == OSLIB_HWND_OBJECT) {
00044 hwndParent = HWND_OBJECT;
00045 }
00046 return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
00047 }
00048
00049
00050 BOOL OSLibWinSetOwner(HWND hwnd, HWND hwndOwner)
00051 {
00052 return WinSetOwner(hwnd, hwndOwner);
00053 }
00054
00055
00056 HWND OSLibWinCreateWindow(HWND hwndParent,ULONG dwWinStyle, ULONG dwOSFrameStyle,
00057 char *pszName, HWND Owner, ULONG fHWND_BOTTOM,
00058 ULONG id, BOOL fTaskList,BOOL fShellPosition,
00059 int classStyle, HWND *hwndFrame)
00060 {
00061 HWND hwndClient;
00062 ULONG dwFrameStyle = 0;
00063
00064 if(pszName && *pszName == 0) {
00065 pszName = NULL;
00066 }
00067 if(hwndParent == OSLIB_HWND_DESKTOP) {
00068 hwndParent = HWND_DESKTOP;
00069 }
00070 if(Owner == OSLIB_HWND_DESKTOP) {
00071 Owner = HWND_DESKTOP;
00072 }
00073
00074 if(classStyle & CS_SAVEBITS_W) dwWinStyle |= WS_SAVEBITS;
00075 if(classStyle & CS_PARENTDC_W) dwWinStyle |= WS_PARENTCLIP;
00076
00077 dwWinStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
00078
00079 if(fTaskList)
00080 {
00081 dwFrameStyle |= FCF_NOMOVEWITHOWNER;
00082 }
00083 if (fShellPosition) dwFrameStyle |= FCF_SHELLPOSITION;
00084
00085 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
00086 FCData.flCreateFlags = dwFrameStyle;
00087
00088 dprintf(("WinCreateWindow %x %s %x task %d shell %d classstyle %x winstyle %x bottom %d", hwndParent, pszName, id, fTaskList, fShellPosition, classStyle, dwWinStyle, fHWND_BOTTOM));
00089
00090
00091
00092
00093 *hwndFrame = WinCreateWindow(hwndParent,
00094 WIN32_STDFRAMECLASS,
00095 pszName, (dwWinStyle & ~WS_CLIPCHILDREN), 0, 0, 0, 0,
00096 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM : HWND_TOP,
00097 id, (PVOID)&FCData, NULL);
00098 if(fOS2Look && *hwndFrame) {
00099 FCData.flCreateFlags = dwOSFrameStyle;
00100
00101 WinCreateFrameControls(*hwndFrame, &FCData, NULL);
00102 }
00103 hwndClient = WinCreateWindow (*hwndFrame, WIN32_STDCLASS,
00104 NULL, dwWinStyle | WS_VISIBLE, 0, 0, 0, 0,
00105 *hwndFrame, HWND_TOP, FID_CLIENT, NULL, NULL);
00106
00107 return hwndClient;
00108 }
00109
00110
00111
00112 BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
00113 {
00114 *OSWinStyle = 0;
00115 *OSFrameStyle = 0;
00116
00117
00118 if(dwStyle & WS_DISABLED_W)
00119 *OSWinStyle |= WS_DISABLED;
00120 if(dwStyle & WS_CLIPSIBLINGS_W)
00121 *OSWinStyle |= WS_CLIPSIBLINGS;
00122 if(dwStyle & WS_CLIPCHILDREN_W)
00123 *OSWinStyle |= WS_CLIPCHILDREN;
00124
00125 if(fOS2Look) {
00126 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
00127 *OSFrameStyle = FCF_TITLEBAR;
00128 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
00129 {
00130 *OSFrameStyle |= FCF_SYSMENU;
00131 }
00132 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
00133 *OSFrameStyle |= FCF_MINMAX;
00134 }
00135 else
00136 if(dwStyle & WS_SYSMENU_W) {
00137 *OSFrameStyle |= FCF_CLOSEBUTTON;
00138 }
00139 }
00140 }
00141 return TRUE;
00142 }
00143
00144
00145 BOOL OSLibWinPositionFrameControls(HWND hwndFrame, RECTLOS2 *pRect, DWORD dwStyle,
00146 DWORD dwExStyle, HICON hSysMenuIcon)
00147 {
00148 SWP swp[3];
00149 HWND hwndControl;
00150 int i = 0;
00151 static int minmaxwidth = 0;
00152 static int minmaxheight = 0;
00153
00154 if(minmaxwidth == 0) {
00155 minmaxwidth = WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON);
00156 minmaxheight = WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
00157 }
00158
00159 if(fOS2Look == OS2_APPEARANCE_SYSMENU) {
00160 hwndControl = WinWindowFromID(hwndFrame, FID_SYSMENU);
00161 if(hwndControl) {
00162 swp[i].hwnd = hwndControl;
00163 swp[i].hwndInsertBehind = HWND_TOP;
00164 swp[i].x = pRect->xLeft;
00165 swp[i].y = pRect->yBottom;
00166 if(pRect->yTop - pRect->yBottom > minmaxheight) {
00167 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
00168 }
00169 swp[i].cx = minmaxwidth/2;
00170 swp[i].cy = minmaxheight;;
00171 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
00172 dprintf(("FID_SYSMENU (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
00173 pRect->xLeft += minmaxwidth/2;
00174 i++;
00175 }
00176 }
00177 else
00178 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W) && hSysMenuIcon) {
00179 pRect->xLeft += minmaxwidth/2;
00180 }
00181
00182 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
00183 hwndControl = WinWindowFromID(hwndFrame, FID_TITLEBAR);
00184 if(hwndControl) {
00185 swp[i].hwnd = hwndControl;
00186 swp[i].hwndInsertBehind = HWND_TOP;
00187 swp[i].x = pRect->xLeft;
00188 swp[i].y = pRect->yBottom;
00189 if(pRect->yTop - pRect->yBottom > minmaxheight) {
00190 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
00191 }
00192 swp[i].cx = pRect->xRight - pRect->xLeft;
00193 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
00194 swp[i].cx -= minmaxwidth;
00195 }
00196
00197 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3) {
00198 swp[i].cx -= minmaxwidth/2;
00199 }
00200 swp[i].cy = minmaxheight;
00201 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
00202 dprintf(("FID_TITLEBAR (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
00203 pRect->xLeft += swp[i].cx;
00204 i++;
00205 }
00206 else return FALSE;
00207 }
00208 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W) || (dwStyle & WS_SYSMENU_W)) {
00209 hwndControl = WinWindowFromID(hwndFrame, FID_MINMAX);
00210 if(hwndControl) {
00211 swp[i].hwnd = hwndControl;
00212 swp[i].hwndInsertBehind = HWND_TOP;
00213 swp[i].x = pRect->xLeft;
00214 swp[i].y = pRect->yBottom;
00215 if(pRect->yTop - pRect->yBottom > minmaxheight) {
00216 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
00217 }
00218 swp[i].cx = 0;
00219 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
00220 swp[i].cx += minmaxwidth;
00221 }
00222
00223 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3) {
00224 swp[i].cx += minmaxwidth/2;
00225 }
00226 swp[i].cy = minmaxheight;
00227 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
00228 dprintf(("FID_MINMAX (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
00229 pRect->xLeft += swp[i].cx;
00230 i++;
00231 }
00232 }
00233 return WinSetMultWindowPos(GetThreadHAB(), swp, i);
00234 }
00235
00236
00237 BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
00238 {
00239 if(offset == OSLIB_QWL_USER)
00240 offset = QWL_USER;
00241
00242 return WinSetWindowULong(hwnd, offset, value);
00243 }
00244
00245
00246 ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
00247 {
00248 if(offset == OSLIB_QWL_USER)
00249 offset = QWL_USER;
00250
00251 return WinQueryWindowULong(hwnd, offset);
00252 }
00253
00254
00255 BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
00256 {
00257 return WinAlarm(hwndDeskTop,flStyle);
00258 }
00259
00260 HWND OSLibWinQueryFocus(HWND hwndDeskTop)
00261 {
00262 return WinQueryFocus(hwndDeskTop);
00263 }
00264
00265
00266 HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
00267 {
00268 return WinWindowFromID(hwndParent,id);
00269 }
00270
00271
00272 BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate)
00273 {
00274 return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? 0 : FC_NOSETACTIVE);
00275 }
00276
00277
00278 BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf)
00279 {
00280 return WinIsChild (hwnd, hwndOf);
00281 }
00282
00283
00284 ULONG OSLibGetWindowHeight(HWND hwnd)
00285 {
00286 RECTL rect;
00287
00288 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
00289 }
00290
00291
00292 LONG OSLibWinQuerySysValue(LONG iSysValue)
00293 {
00294 return WinQuerySysValue(HWND_DESKTOP,iSysValue);
00295 }
00296
00297
00298 BOOL OSLibWinSetSysValue(LONG iSysValue, ULONG val)
00299 {
00300 return WinQuerySysValue(iSysValue, val);
00301 }
00302
00303
00304 ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
00305 {
00306 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
00307 }
00308
00309
00310 BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
00311 {
00312 return WinSetDlgItemText(hwndDlg,idItem,pszText);
00313 }
00314
00315
00316 BOOL OSLibWinQueryPointerPos(PPOINT pptlPoint)
00317 {
00318 return WinQueryPointerPos(HWND_DESKTOP,(PPOINTL)pptlPoint);
00319 }
00320
00321
00322 BOOL OSLibWinSetPointerPos(int x, int y)
00323 {
00324 return WinSetPointerPos(HWND_DESKTOP, x, y);
00325 }
00326
00327
00328 HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
00329 {
00330 return WinQueryWindow(hwnd, lCode);
00331 }
00332
00333
00334 BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
00335 {
00336 return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
00337 }
00338
00339
00340 BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
00341 {
00342 BOOL rc = 1;
00343
00344 if(fl & SWP_SHOW) {
00345 rc = WinShowWindow(hwnd, TRUE);
00346 }
00347 if(rc == 0)
00348 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
00349 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, fl);
00350 if(rc == 0)
00351 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
00352 return rc;
00353 }
00354
00355
00356 BOOL OSLibWinDestroyWindow(HWND hwnd)
00357 {
00358 return WinDestroyWindow(hwnd);
00359 }
00360
00361
00362 BOOL OSLibWinQueryWindowClientRect(HWND hwndOS2, PRECT pRect)
00363 {
00364 BOOL rc;
00365 RECTLOS2 rectl;
00366
00367 rc = WinQueryWindowRect(hwndOS2, (PRECTL)&rectl);
00368 if(rc) {
00369 pRect->left = 0;
00370 pRect->right = rectl.xRight - rectl.xLeft;
00371 pRect->top = 0;
00372 pRect->bottom = rectl.yTop - rectl.yBottom;
00373 }
00374 else memset(pRect, 0, sizeof(RECT));
00375 return rc;
00376 }
00377
00378
00379 BOOL OSLibQueryWindowRectAbsolute (HWND hwndOS2, PRECT pRect)
00380 {
00381 BOOL rc;
00382 RECTLOS2 rectl;
00383
00384 rc = WinQueryWindowRect (hwndOS2, (RECTL *)&rectl);
00385 if (rc)
00386 {
00387 rc = WinMapWindowPoints (hwndOS2, HWND_DESKTOP, (POINTL *)&rectl, 2);
00388 if (rc)
00389 {
00390 pRect->left = rectl.xLeft;
00391 pRect->right = rectl.xRight;
00392 pRect->top = mapScreenY (rectl.yTop);
00393 pRect->bottom = mapScreenY (rectl.yBottom);
00394 }
00395 }
00396 if (!rc)
00397 {
00398 memset(pRect, 0, sizeof(*pRect));
00399 }
00400 return rc;
00401 }
00402
00403
00404 #if 0
00405 BOOL OSLibWinQueryWindowRect(Win32BaseWindow *window, PRECT pRect, int RelativeTo)
00406 {
00407 BOOL rc;
00408 RECTLOS2 rectl;
00409
00410 rc = WinQueryWindowRect(window->getOS2WindowHandle(), (PRECTL)&rectl);
00411 if(rc) {
00412 if(RelativeTo == RELATIVE_TO_SCREEN) {
00413 mapOS2ToWin32RectFrame(window,windowDesktop,&rectl,pRect);
00414 }
00415 else mapOS2ToWin32RectFrame(window,&rectl,pRect);
00416 }
00417 else memset(pRect, 0, sizeof(RECT));
00418 return rc;
00419 }
00420 #endif
00421
00422
00423 BOOL OSLibWinIsIconic(HWND hwnd)
00424 {
00425 SWP swp;
00426 BOOL rc;
00427
00428 rc = WinQueryWindowPos(hwnd, &swp);
00429 if(rc == FALSE) {
00430 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
00431 return FALSE;
00432 }
00433
00434 if(swp.fl & SWP_MINIMIZE)
00435 return TRUE;
00436 else return FALSE;
00437 }
00438
00439
00440 BOOL OSLibWinSetActiveWindow(HWND hwnd)
00441 {
00442 BOOL rc;
00443
00444 rc = WinSetActiveWindow(HWND_DESKTOP, hwnd);
00445 if(rc == FALSE) {
00446 dprintf(("WinSetActiveWindow %x failure: %x", hwnd, OSLibWinGetLastError()));
00447 }
00448 return rc;
00449 }
00450
00451
00452 BOOL OSLibWinSetFocus(HWND hwnd)
00453 {
00454 return WinSetFocus(HWND_DESKTOP, hwnd);
00455 }
00456
00457
00458 BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
00459 {
00460 BOOL rc;
00461 HWND hwndClient;
00462
00463 rc = WinEnableWindow(hwnd, fEnable);
00464 hwndClient = WinWindowFromID(hwnd, FID_CLIENT);
00465 if(hwndClient) {
00466 WinEnableWindow(hwndClient, fEnable);
00467 }
00468 return rc;
00469 }
00470
00471
00472 BOOL OSLibWinIsWindowEnabled(HWND hwnd)
00473 {
00474 return WinIsWindowEnabled(hwnd);
00475 }
00476
00477
00478 BOOL OSLibWinIsWindowVisible(HWND hwnd)
00479 {
00480 return WinIsWindowVisible(hwnd);
00481 }
00482
00483
00484 HWND OSLibWinQueryActiveWindow()
00485 {
00486 return WinQueryActiveWindow(HWND_DESKTOP);
00487 }
00488
00489
00490 LONG OSLibWinQueryWindowTextLength(HWND hwnd)
00491 {
00492 return WinQueryWindowTextLength(hwnd);
00493 }
00494
00495
00496 LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
00497 {
00498 return WinQueryWindowText(hwnd, length, lpsz);
00499 }
00500
00501
00502 BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
00503 {
00504 return WinSetWindowText(hwnd, lpsz);
00505 }
00506
00507
00508 BOOL OSLibWinSetTitleBarText(HWND hwnd, LPSTR lpsz)
00509 {
00510 return WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), lpsz);
00511 }
00512
00513
00514 BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
00515 {
00516 return WinFlashWindow(hwnd, fFlash);
00517 }
00518
00519
00520 HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
00521 {
00522 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
00523 }
00524
00525
00526 BOOL OSLibWinMinimizeWindow(HWND hwnd)
00527 {
00528 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
00529 }
00530
00531
00532 BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
00533 {
00534 pointl->x = 0;
00535 pointl->y = 0;
00536 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
00537 }
00538
00539
00540 BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
00541 {
00542 ULONG hIconOS2 = GetOS2Icon(hIcon);
00543 if(hIconOS2)
00544 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIconOS2, 0);
00545 return FALSE;
00546 }
00547
00548
00549 BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
00550 {
00551 return WinQueryWindowPos(hwnd, pswp);
00552 }
00553
00554
00555 void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld,
00556 int parentHeight, HWND hwnd)
00557 {
00558 HWND hWindow = pswp->hwnd;
00559 HWND hWndInsertAfter = pswp->hwndInsertBehind;
00560 long x = pswp->x;
00561 long y = pswp->y;
00562 long cx = pswp->cx;
00563 long cy = pswp->cy;
00564 UINT fuFlags = (UINT)pswp->fl;
00565
00566 HWND hWinAfter;
00567 ULONG flags = 0;
00568
00569 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
00570
00571 if (hWndInsertAfter == HWND_TOP)
00572 hWinAfter = HWND_TOP_W;
00573 else if (hWndInsertAfter == HWND_BOTTOM)
00574 hWinAfter = HWND_BOTTOM_W;
00575 else
00576 hWinAfter = (HWND) hWndInsertAfter;
00577
00578
00579
00580
00581 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
00582 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
00583 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
00584 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
00585 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
00586 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
00587 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
00588 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
00589
00590 if(fuFlags & (SWP_MOVE | SWP_SIZE))
00591 {
00592 y = parentHeight - y - pswp->cy;
00593
00594 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
00595 flags |= SWP_NOMOVE_W;
00596
00597 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
00598 flags |= SWP_NOSIZE_W;
00599
00600 if (fuFlags & SWP_SIZE)
00601 {
00602 if (pswp->cy != pswpOld->cy)
00603 {
00604 flags &= ~SWP_NOMOVE_W;
00605 }
00606 }
00607 }
00608
00609 pswpOld->x = pswp->x;
00610 pswpOld->y = parentHeight-pswp->y-pswp->cy;
00611 pswpOld->cx = pswp->cx;
00612 pswpOld->cy = pswp->cy;
00613
00614 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
00615 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
00616
00617 pwpos->flags = (UINT)flags;
00618 pwpos->cy = cy;
00619 pwpos->cx = cx;
00620 pwpos->x = x;
00621 pwpos->y = y;
00622 pwpos->hwndInsertAfter = hWinAfter;
00623 pwpos->hwnd = hWindow;
00624 }
00625
00626
00627 void OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld,
00628 int parentHeight, HWND hFrame)
00629 {
00630 BOOL fCvt = FALSE;
00631
00632 HWND hWnd = pwpos->hwnd;
00633 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
00634 long x = pwpos->x;
00635 long y = pwpos->y;
00636 long cx = pwpos->cx;
00637 long cy = pwpos->cy;
00638 UINT fuFlags = pwpos->flags;
00639
00640 HWND hWinAfter;
00641 ULONG flags = 0;
00642 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
00643
00644 if (hWndInsertAfter == HWND_TOPMOST_W)
00645
00646 hWinAfter = HWND_TOP;
00647 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
00648
00649 hWinAfter = HWND_TOP;
00650 else if (hWndInsertAfter == HWND_TOP_W)
00651 hWinAfter = HWND_TOP;
00652 else if (hWndInsertAfter == HWND_BOTTOM_W)
00653 hWinAfter = HWND_BOTTOM;
00654 else
00655 hWinAfter = (HWND) hWndInsertAfter;
00656
00657 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
00658 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
00659 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
00660 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
00661 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
00662 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
00663 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
00664 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
00665
00666 if(flags & (SWP_MOVE | SWP_SIZE))
00667 {
00668 if((flags & SWP_MOVE) == 0)
00669 {
00670 x = pswpOld->x;
00671 y = pswpOld->y;
00672
00673 y = parentHeight - y - pswpOld->cy;
00674 }
00675
00676 if(flags & SWP_SIZE)
00677 {
00678 if (cy != pswpOld->cy)
00679 flags |= SWP_MOVE;
00680 }
00681 else
00682 {
00683 cx = pswpOld->cx;
00684 cy = pswpOld->cy;
00685 }
00686 y = parentHeight - y - cy;
00687
00688 if ((pswpOld->x == x) && (pswpOld->y == y))
00689 flags &= ~SWP_MOVE;
00690
00691 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
00692 flags &= ~SWP_SIZE;
00693 }
00694
00695 pswp->fl = flags;
00696 pswp->cy = cy;
00697 pswp->cx = cx;
00698 pswp->x = x;
00699 pswp->y = y;
00700 pswp->hwndInsertBehind = hWinAfter;
00701 pswp->hwnd = hWindow;
00702 pswp->ulReserved1 = 0;
00703 pswp->ulReserved2 = 0;
00704 }
00705
00706
00707 void OSLibWinSetClientPos(HWND hwnd, int x, int y, int cx, int cy, int parentHeight)
00708 {
00709 SWP swp;
00710 BOOL rc;
00711
00712 swp.hwnd = hwnd;
00713 swp.hwndInsertBehind = 0;
00714 swp.x = x;
00715 swp.y = parentHeight - y - cy;
00716 swp.cx = cx;
00717 swp.cy = cy;
00718 swp.fl = SWP_MOVE | SWP_SIZE;
00719
00720 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));
00721
00722 rc = WinSetMultWindowPos(GetThreadHAB(), &swp, 1);
00723 if(rc == FALSE) {
00724 dprintf(("OSLibWinSetClientPos: WinSetMultWindowPos %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
00725 }
00726 }
00727
00728
00729 BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
00730 {
00731 BOOL rc;
00732
00733 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
00734
00735 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
00736 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
00737
00738 return rc;
00739 }
00740
00741
00742 BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
00743 {
00744 TRACKINFO tinfo;
00745
00746 memset(&tinfo, 0, sizeof(TRACKINFO));
00747 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
00748
00749 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
00750 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
00751 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
00752 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
00753 return TRUE;
00754 }
00755
00756
00757 HWND OSLibWinBeginEnumWindows(HWND hwnd)
00758 {
00759 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
00760 else
00761 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
00762
00763 return WinBeginEnumWindows(hwnd);
00764 }
00765
00766
00767 HWND OSLibWinGetNextWindow(HWND hwndEnum)
00768 {
00769 return WinGetNextWindow(hwndEnum);
00770 }
00771
00772
00773 HWND OSLibWinQueryClientWindow(HWND hwndFrame)
00774 {
00775 HWND hwndClient = 0;
00776
00777 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
00778 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
00779
00780 return hwndClient;
00781 }
00782
00783
00784 BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
00785 {
00786 return WinEndEnumWindows(hwndEnum);
00787 }
00788
00789
00790 BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
00791 {
00792 return WinQueryWindowProcess(hwnd, pid, tid);
00793 }
00794
00795
00796 BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
00797 {
00798 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
00799 }
00800
00801
00802 HWND OSLibWinQueryObjectWindow(VOID)
00803 {
00804 return WinQueryObjectWindow(HWND_DESKTOP);
00805 }
00806
00807
00808 HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
00809 {
00810 HWND hwndNext, hwndFound=0;
00811 HENUM henum;
00812
00813 henum = WinBeginEnumWindows(HWND_OBJECT);
00814 while ((hwndNext = WinGetNextWindow(henum)) != 0)
00815 {
00816 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
00817 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
00818 {
00819 hwndFound = hwndNext;
00820 break;
00821 }
00822 }
00823 WinEndEnumWindows(henum);
00824 return hwndFound;
00825 }
00826
00827
00828 BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
00829 {
00830 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
00831 return WinSetWindowULong(hwnd, QWS_ID, value);
00832 }
00833
00834
00835 PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
00836 {
00837 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
00838 }
00839
00840
00841 BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
00842 {
00843 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
00844
00845 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
00846 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
00847 (pRect->bottom - pRect->top)));
00848 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
00849 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
00850 return TRUE;
00851 }
00852
00853
00854 BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
00855 {
00856 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
00857
00858 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
00859 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
00860 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
00861 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
00862 return TRUE;
00863 }
00864
00865
00866 BOOL OSLibWinGetKeyboardStateTable(unsigned char *PMKeyState)
00867 {
00868 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, FALSE );
00869 }
00870
00871
00872 BOOL OSLibWinSetKeyboardStateTable(unsigned char *PMKeyState)
00873 {
00874 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, TRUE );
00875 }
00876
00877
00878 USHORT APIENTRY WinTranslateChar2( USHORT
00879 , PUSHORT
00880 , PULONG
00881 , USHORT
00882 , PUSHORT
00883 );
00884
00885
00886 USHORT OSLibWinTranslateChar(USHORT usScanCode, ULONG type, USHORT shiftstate)
00887 {
00888 USHORT sel = GetFS();
00889 usScanCode = WinTranslateChar2(0, &usScanCode, NULL, type, &shiftstate);
00890 SetFS(sel);
00891 return usScanCode;
00892 }
00893
00894
00895 BOOL OSLibWinEnableWindowUpdate(HWND hwndFrame, HWND hwndClient ,BOOL fEnable)
00896 {
00897 WinEnableWindowUpdate(hwndFrame, fEnable);
00898 return WinEnableWindowUpdate(hwndClient, fEnable);
00899 }
00900
00901
00902 ULONG OSLibWinGetLastError()
00903 {
00904 return WinGetLastError(GetThreadHAB()) & 0xFFFF;
00905 }
00906
00907
00908 void OSLibWinShowTaskList(HWND hwndFrame)
00909 {
00910
00911 WinSetActiveWindow(HWND_DESKTOP,0x8000000E);
00912 }
00913
00914
00915 void OSLibSetWindowStyle(HWND hwndFrame, HWND hwndClient, ULONG dwStyle, ULONG dwExStyle)
00916 {
00917 ULONG dwWinStyle;
00918 ULONG dwOldWinStyle;
00919
00920
00921 dwWinStyle = WinQueryWindowULong(hwndClient, QWL_STYLE);
00922 dwOldWinStyle = dwWinStyle;
00923
00924 if(dwStyle & WS_CLIPCHILDREN_W) {
00925 dwWinStyle |= WS_CLIPCHILDREN;
00926 }
00927 else dwWinStyle &= ~WS_CLIPCHILDREN;
00928
00929 if(dwWinStyle != dwOldWinStyle) {
00930 WinSetWindowULong(hwndClient, QWL_STYLE, dwWinStyle);
00931 }
00932
00933
00934 dwWinStyle = WinQueryWindowULong(hwndFrame, QWL_STYLE);
00935 dwOldWinStyle = dwWinStyle;
00936 if(dwStyle & WS_DISABLED_W) {
00937 dwWinStyle |= WS_DISABLED;
00938 }
00939 else dwWinStyle &= ~WS_DISABLED;
00940
00941 if(dwStyle & WS_CLIPSIBLINGS_W) {
00942 dwWinStyle |= WS_CLIPSIBLINGS;
00943 }
00944 else dwWinStyle &= ~WS_CLIPSIBLINGS;
00945
00946 if(dwStyle & WS_MINIMIZE_W) {
00947 dwWinStyle |= WS_MINIMIZED;
00948 }
00949 else dwWinStyle &= ~WS_MINIMIZED;
00950
00951 if(dwStyle & WS_MAXIMIZE_W) {
00952 dwWinStyle |= WS_MAXIMIZED;
00953 }
00954 else dwWinStyle &= ~WS_MAXIMIZED;
00955
00956 if(dwWinStyle != dwOldWinStyle) {
00957 WinSetWindowULong(hwndFrame, QWL_STYLE, dwWinStyle);
00958 }
00959 if(fOS2Look) {
00960 ULONG OSFrameStyle = 0;
00961 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
00962 if(WinWindowFromID(hwndFrame, FID_TITLEBAR) == 0) {
00963 OSFrameStyle = FCF_TITLEBAR;
00964 }
00965 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
00966 {
00967 if(WinWindowFromID(hwndFrame, FID_SYSMENU) == 0) {
00968 OSFrameStyle |= FCF_SYSMENU;
00969 }
00970 }
00971 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
00972 if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) {
00973 OSFrameStyle |= FCF_MINMAX;
00974 }
00975 }
00976 else
00977 if(dwStyle & WS_SYSMENU_W) {
00978 if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) {
00979 OSFrameStyle |= FCF_CLOSEBUTTON;
00980 }
00981 }
00982 }
00983 if(OSFrameStyle) {
00984 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
00985
00986 FCData.flCreateFlags = OSFrameStyle;
00987 WinCreateFrameControls(hwndFrame, &FCData, NULL);
00988 }
00989 }
00990 }
00991
00992
00993 DWORD OSLibQueryWindowStyle(HWND hwnd)
00994 {
00995 return WinQueryWindowULong(hwnd, QWL_STYLE);
00996 }
00997
00998
00999 void OSLibWinSetVisibleRegionNotify(HWND hwnd, BOOL fNotify)
01000 {
01001 WinSetVisibleRegionNotify(hwnd, fNotify);
01002 }
01003
01004
01005 HWND OSLibWinQueryCapture()
01006 {
01007 return WinQueryCapture(HWND_DESKTOP);
01008 }
01009
01010
01011 BOOL OSLibWinSetCapture(HWND hwnd)
01012 {
01013 return WinSetCapture(HWND_DESKTOP, hwnd);
01014 }
01015
01016
01017 BOOL OSLibWinRemoveFromTasklist(HANDLE hTaskList)
01018 {
01019 return (WinRemoveSwitchEntry(hTaskList)) ? FALSE : TRUE;
01020 }
01021
01022
01023 HANDLE OSLibWinAddToTaskList(HWND hwndFrame, char *title, BOOL fVisible)
01024 {
01025 SWCNTRL swctrl;
01026 ULONG tid;
01027
01028 swctrl.hwnd = hwndFrame;
01029 swctrl.hwndIcon = 0;
01030 swctrl.hprog = 0;
01031 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
01032 swctrl.idSession = 0;
01033 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
01034 swctrl.fbJump = SWL_JUMPABLE;
01035 swctrl.bProgType = PROG_PM;
01036 if(title) {
01037 strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
01038 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
01039 }
01040 else {
01041 swctrl.szSwtitle[0] = 0;
01042 swctrl.uchVisibility = SWL_INVISIBLE;
01043 }
01044 return WinAddSwitchEntry(&swctrl);
01045 }
01046
01047
01048 BOOL OSLibWinChangeTaskList(HANDLE hTaskList, HWND hwndFrame, char *title, BOOL fVisible)
01049 {
01050 SWCNTRL swctrl;
01051 ULONG tid;
01052
01053 swctrl.hwnd = hwndFrame;
01054 swctrl.hwndIcon = 0;
01055 swctrl.hprog = 0;
01056 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
01057 swctrl.idSession = 0;
01058 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
01059 swctrl.fbJump = SWL_JUMPABLE;
01060 swctrl.bProgType = PROG_PM;
01061 if(title) {
01062 strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
01063 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
01064 }
01065 else {
01066 swctrl.szSwtitle[0] = 0;
01067 swctrl.uchVisibility = SWL_INVISIBLE;
01068 }
01069 return (WinChangeSwitchEntry(hTaskList, &swctrl)) ? FALSE : TRUE;
01070 }
01071
01072
01073 BOOL OSLibWinLockWindowUpdate(HWND hwnd)
01074 {
01075 return WinLockWindowUpdate(HWND_DESKTOP, (HWND)hwnd);
01076 }
01077
01078
01079 ULONG OSLibGetScreenHeight()
01080 {
01081 return ScreenHeight;
01082 }
01083
01084
01085 ULONG OSLibGetScreenWidth()
01086 {
01087 return ScreenWidth;
01088 }
01089
01090
01091
01092
01093 BOOL OSLibWinGetMaxPosition(HWND hwndOS2, RECT *rect)
01094 {
01095 SWP swp;
01096
01097 if(!WinGetMaxPosition(hwndOS2, &swp)) {
01098 dprintf(("WARNING: WinGetMaxPosition %x returned FALSE", hwndOS2));
01099 return FALSE;
01100 }
01101 rect->left = swp.x;
01102 rect->right = swp.x + swp.cx;
01103 rect->top = ScreenHeight - (swp.y + swp.cy);
01104 rect->bottom = ScreenHeight - swp.y;
01105 return TRUE;
01106 }
01107
01108
01109 BOOL OSLibWinShowPointer(BOOL fShow)
01110 {
01111 return WinShowPointer(HWND_DESKTOP, fShow);
01112 }
01113
01114
01115 ULONG OSLibWinQuerySysColor(int index)
01116 {
01117 return CONVERT_RGB(WinQuerySysColor(HWND_DESKTOP, index, 0));
01118 }
01119
01120