| 1 | /* $Id: oslibwin.cpp,v 1.22 1999-08-20 20:09:51 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Window API wrappers for OS/2
|
|---|
| 4 | *
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 | #define INCL_WIN
|
|---|
| 13 | #define INCL_PM
|
|---|
| 14 | #include <os2.h>
|
|---|
| 15 | #include <os2wrap.h>
|
|---|
| 16 | #include <stdlib.h>
|
|---|
| 17 | #include <string.h>
|
|---|
| 18 |
|
|---|
| 19 | #include <misc.h>
|
|---|
| 20 | #include <winconst.h>
|
|---|
| 21 | #include "oslibwin.h"
|
|---|
| 22 | #include "oslibutil.h"
|
|---|
| 23 | #include "oslibmsg.h"
|
|---|
| 24 | #include "oslibgdi.h"
|
|---|
| 25 | #include "pmwindow.h"
|
|---|
| 26 |
|
|---|
| 27 | //******************************************************************************
|
|---|
| 28 | //******************************************************************************
|
|---|
| 29 | BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
|
|---|
| 30 | {
|
|---|
| 31 | if(hwndParent == OSLIB_HWND_DESKTOP)
|
|---|
| 32 | {
|
|---|
| 33 | hwndParent = HWND_DESKTOP;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
|
|---|
| 37 | }
|
|---|
| 38 | //******************************************************************************
|
|---|
| 39 | //******************************************************************************
|
|---|
| 40 | HWND OSLibWinCreateWindow(HWND hwndParent, ULONG dwWinStyle, ULONG dwFrameStyle,
|
|---|
| 41 | char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame)
|
|---|
| 42 | {
|
|---|
| 43 | HWND hwndClient;
|
|---|
| 44 |
|
|---|
| 45 | dprintf(("WinCreateWindow %x %x %x %s", hwndParent, dwWinStyle, dwFrameStyle, pszName));
|
|---|
| 46 |
|
|---|
| 47 | if(pszName && *pszName == 0) {
|
|---|
| 48 | pszName = NULL;
|
|---|
| 49 | }
|
|---|
| 50 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
|---|
| 51 | hwndParent = HWND_DESKTOP;
|
|---|
| 52 | }
|
|---|
| 53 | if(Owner == OSLIB_HWND_DESKTOP) {
|
|---|
| 54 | Owner = HWND_DESKTOP;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | if(dwFrameStyle) {
|
|---|
| 58 | dwWinStyle &= ~WS_CLIPCHILDREN; //invalid style according to docs
|
|---|
| 59 | if(pszName)
|
|---|
| 60 | dwFrameStyle |= FCF_TITLEBAR;
|
|---|
| 61 |
|
|---|
| 62 | dwFrameStyle |= FCF_TASKLIST;
|
|---|
| 63 | *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
|
|---|
| 64 | &dwFrameStyle, WIN32_STDCLASS,
|
|---|
| 65 | "", 0, 0, 0, &hwndClient);
|
|---|
| 66 | if(*hwndFrame) {
|
|---|
| 67 | if(pszName) {
|
|---|
| 68 | WinSetWindowText(*hwndFrame, pszName);
|
|---|
| 69 | }
|
|---|
| 70 | return hwndClient;
|
|---|
| 71 | }
|
|---|
| 72 | dprintf(("OSLibWinCreateWindow: WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
|
|---|
| 73 | return 0;
|
|---|
| 74 | }
|
|---|
| 75 | hwndClient = WinCreateWindow(hwndParent, WIN32_STDCLASS, pszName, dwWinStyle, 0, 0, 0, 0,
|
|---|
| 76 | Owner, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP, 0, NULL,
|
|---|
| 77 | NULL);
|
|---|
| 78 | *hwndFrame = hwndClient;
|
|---|
| 79 | return hwndClient;
|
|---|
| 80 | }
|
|---|
| 81 | //******************************************************************************
|
|---|
| 82 | //******************************************************************************
|
|---|
| 83 | BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
|
|---|
| 84 | {
|
|---|
| 85 | *OSWinStyle = 0;
|
|---|
| 86 | *OSFrameStyle = 0;
|
|---|
| 87 |
|
|---|
| 88 | /* Window styles */
|
|---|
| 89 | if(dwStyle & WS_MINIMIZE_W)
|
|---|
| 90 | *OSWinStyle |= WS_MINIMIZED;
|
|---|
| 91 | //Done explicitely in CreateWindowExA
|
|---|
| 92 | #if 0
|
|---|
| 93 | if(dwStyle & WS_VISIBLE_W)
|
|---|
| 94 | *OSWinStyle |= WS_VISIBLE;
|
|---|
| 95 | #endif
|
|---|
| 96 | if(dwStyle & WS_DISABLED_W)
|
|---|
| 97 | *OSWinStyle |= WS_DISABLED;
|
|---|
| 98 | if(dwStyle & WS_CLIPSIBLINGS_W)
|
|---|
| 99 | *OSWinStyle |= WS_CLIPSIBLINGS;
|
|---|
| 100 | if(dwStyle & WS_CLIPCHILDREN_W)
|
|---|
| 101 | *OSWinStyle |= WS_CLIPCHILDREN;
|
|---|
| 102 | if(dwStyle & WS_MAXIMIZE_W)
|
|---|
| 103 | *OSWinStyle |= WS_MAXIMIZED;
|
|---|
| 104 | if(dwStyle & WS_GROUP_W)
|
|---|
| 105 | *OSWinStyle |= WS_GROUP;
|
|---|
| 106 | if(dwStyle & WS_TABSTOP_W)
|
|---|
| 107 | *OSWinStyle |= WS_TABSTOP;
|
|---|
| 108 |
|
|---|
| 109 | if(dwStyle & WS_CAPTION_W)
|
|---|
| 110 | *OSFrameStyle |= FCF_TITLEBAR;
|
|---|
| 111 | if(dwStyle & WS_DLGFRAME_W)
|
|---|
| 112 | *OSFrameStyle |= FCF_DLGBORDER;
|
|---|
| 113 | else
|
|---|
| 114 | if(dwStyle & WS_BORDER_W)
|
|---|
| 115 | *OSFrameStyle |= FCF_BORDER;
|
|---|
| 116 |
|
|---|
| 117 | if(dwStyle & WS_VSCROLL_W)
|
|---|
| 118 | *OSFrameStyle |= FCF_VERTSCROLL;
|
|---|
| 119 | if(dwStyle & WS_HSCROLL_W)
|
|---|
| 120 | *OSFrameStyle |= FCF_HORZSCROLL;
|
|---|
| 121 | if(dwStyle & WS_SYSMENU_W)
|
|---|
| 122 | *OSFrameStyle |= FCF_SYSMENU;
|
|---|
| 123 | if(dwStyle & WS_THICKFRAME_W)
|
|---|
| 124 | *OSFrameStyle |= FCF_SIZEBORDER; //??
|
|---|
| 125 | if(dwStyle & WS_MINIMIZEBOX_W)
|
|---|
| 126 | *OSFrameStyle |= FCF_MINBUTTON;
|
|---|
| 127 | if(dwStyle & WS_MAXIMIZEBOX_W)
|
|---|
| 128 | *OSFrameStyle |= FCF_MAXBUTTON;
|
|---|
| 129 |
|
|---|
| 130 | if(dwExStyle & WS_EX_DLGMODALFRAME_W)
|
|---|
| 131 | *OSFrameStyle |= FCF_DLGBORDER;
|
|---|
| 132 |
|
|---|
| 133 | return TRUE;
|
|---|
| 134 | }
|
|---|
| 135 | //******************************************************************************
|
|---|
| 136 | //******************************************************************************
|
|---|
| 137 | BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
|
|---|
| 138 | {
|
|---|
| 139 | return WinSetWindowULong(hwnd, offset, value);
|
|---|
| 140 | }
|
|---|
| 141 | //******************************************************************************
|
|---|
| 142 | //******************************************************************************
|
|---|
| 143 | ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
|
|---|
| 144 | {
|
|---|
| 145 | return WinQueryWindowULong(hwnd, offset);
|
|---|
| 146 | }
|
|---|
| 147 | //******************************************************************************
|
|---|
| 148 | //******************************************************************************
|
|---|
| 149 | BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
|
|---|
| 150 | {
|
|---|
| 151 | return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
|
|---|
| 152 | }
|
|---|
| 153 | //******************************************************************************
|
|---|
| 154 | //******************************************************************************
|
|---|
| 155 | //******************************************************************************
|
|---|
| 156 | //******************************************************************************
|
|---|
| 157 | BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
|
|---|
| 158 | {
|
|---|
| 159 | return WinAlarm(hwndDeskTop,flStyle);
|
|---|
| 160 | }
|
|---|
| 161 | //******************************************************************************
|
|---|
| 162 | //******************************************************************************
|
|---|
| 163 | APIRET OSLibDosBeep(ULONG freg,ULONG dur)
|
|---|
| 164 | {
|
|---|
| 165 | return DosBeep(freg,dur);
|
|---|
| 166 | }
|
|---|
| 167 | //******************************************************************************
|
|---|
| 168 | //******************************************************************************
|
|---|
| 169 | HWND OSLibWinQueryFocus(HWND hwndDeskTop)
|
|---|
| 170 | {
|
|---|
| 171 | return WinQueryFocus(hwndDeskTop);
|
|---|
| 172 | }
|
|---|
| 173 | //******************************************************************************
|
|---|
| 174 | //******************************************************************************
|
|---|
| 175 | HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
|
|---|
| 176 | {
|
|---|
| 177 | return WinWindowFromID(hwndParent,id);
|
|---|
| 178 | }
|
|---|
| 179 | //******************************************************************************
|
|---|
| 180 | //******************************************************************************
|
|---|
| 181 | BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus)
|
|---|
| 182 | {
|
|---|
| 183 | return WinSetFocus(hwndDeskTop,hwndNewFocus);
|
|---|
| 184 | }
|
|---|
| 185 | //******************************************************************************
|
|---|
| 186 | //******************************************************************************
|
|---|
| 187 | ULONG OSLibGetWindowHeight(HWND hwnd)
|
|---|
| 188 | {
|
|---|
| 189 | RECTL rect;
|
|---|
| 190 |
|
|---|
| 191 | return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
|
|---|
| 192 | }
|
|---|
| 193 | //******************************************************************************
|
|---|
| 194 | //******************************************************************************
|
|---|
| 195 | LONG OSLibWinQuerySysValue(HWND hwndDeskTop,LONG iSysValue)
|
|---|
| 196 | {
|
|---|
| 197 | return WinQuerySysValue(hwndDeskTop,iSysValue);
|
|---|
| 198 | }
|
|---|
| 199 | //******************************************************************************
|
|---|
| 200 | //******************************************************************************
|
|---|
| 201 | ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
|
|---|
| 202 | {
|
|---|
| 203 | return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
|
|---|
| 204 | }
|
|---|
| 205 | //******************************************************************************
|
|---|
| 206 | //******************************************************************************
|
|---|
| 207 | BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
|
|---|
| 208 | {
|
|---|
| 209 | return WinSetDlgItemText(hwndDlg,idItem,pszText);
|
|---|
| 210 | }
|
|---|
| 211 | //******************************************************************************
|
|---|
| 212 | //******************************************************************************
|
|---|
| 213 | BOOL OSLibWinQueryPointerPos(HWND hwndDeskTop,PPOINT pptlPoint)
|
|---|
| 214 | {
|
|---|
| 215 | return WinQueryPointerPos(hwndDeskTop,(PPOINTL)pptlPoint);
|
|---|
| 216 | }
|
|---|
| 217 | //******************************************************************************
|
|---|
| 218 | //******************************************************************************
|
|---|
| 219 | HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
|
|---|
| 220 | {
|
|---|
| 221 | return WinQueryWindow(hwnd, lCode);
|
|---|
| 222 | }
|
|---|
| 223 | //******************************************************************************
|
|---|
| 224 | //******************************************************************************
|
|---|
| 225 | BOOL OSLibWinSetWindowPos(HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y, LONG cx,
|
|---|
| 226 | LONG cy, ULONG fl)
|
|---|
| 227 | {
|
|---|
| 228 | HWND hwndParent = hwndInsertBehind;
|
|---|
| 229 | BOOL rc;
|
|---|
| 230 |
|
|---|
| 231 | if(fl & SWP_MOVE) {
|
|---|
| 232 | switch(hwndParent)
|
|---|
| 233 | {
|
|---|
| 234 | case HWNDOS_TOP:
|
|---|
| 235 | case HWNDOS_BOTTOM:
|
|---|
| 236 | hwndParent = HWND_DESKTOP;
|
|---|
| 237 | break;
|
|---|
| 238 | }
|
|---|
| 239 | y = MapOS2ToWin32Y(hwndParent, cy, y);
|
|---|
| 240 | }
|
|---|
| 241 | rc = WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
|
|---|
| 242 | dprintf(("WinSetWindowPos %x %x %d %d %d %d %x returned %d (%x)", hwnd, hwndInsertBehind, x, y, cx, cy, fl, rc, WinGetLastError(GetThreadHAB())));
|
|---|
| 243 | return rc;
|
|---|
| 244 | }
|
|---|
| 245 | //******************************************************************************
|
|---|
| 246 | //******************************************************************************
|
|---|
| 247 | BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
|
|---|
| 248 | {
|
|---|
| 249 | BOOL rc;
|
|---|
| 250 |
|
|---|
| 251 | if(fl & SWP_SHOW) {
|
|---|
| 252 | rc = WinShowWindow(hwnd, TRUE);
|
|---|
| 253 | }
|
|---|
| 254 | if(rc == 0)
|
|---|
| 255 | dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
|
|---|
| 256 | rc = WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, fl);
|
|---|
| 257 | if(rc == 0)
|
|---|
| 258 | dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
|
|---|
| 259 | return rc;
|
|---|
| 260 | }
|
|---|
| 261 | //******************************************************************************
|
|---|
| 262 | //******************************************************************************
|
|---|
| 263 | BOOL OSLibWinDestroyWindow(HWND hwnd)
|
|---|
| 264 | {
|
|---|
| 265 | return WinDestroyWindow(hwnd);
|
|---|
| 266 | }
|
|---|
| 267 | //******************************************************************************
|
|---|
| 268 | //******************************************************************************
|
|---|
| 269 | BOOL OSLibWinQueryWindowRect(HWND hwnd, PRECT pRect, int RelativeTo)
|
|---|
| 270 | {
|
|---|
| 271 | BOOL rc;
|
|---|
| 272 | RECTLOS2 rectl;
|
|---|
| 273 |
|
|---|
| 274 | rc = WinQueryWindowRect(hwnd, (PRECTL)&rectl);
|
|---|
| 275 | if(rc) {
|
|---|
| 276 | if(RelativeTo == RELATIVE_TO_SCREEN) {
|
|---|
| 277 | MapOS2ToWin32Rectl(OSLIB_HWND_DESKTOP, hwnd, &rectl, pRect);
|
|---|
| 278 | }
|
|---|
| 279 | else MapOS2ToWin32Rectl(&rectl, pRect);
|
|---|
| 280 | }
|
|---|
| 281 | else memset(pRect, 0, sizeof(RECT));
|
|---|
| 282 | return rc;
|
|---|
| 283 | }
|
|---|
| 284 | //******************************************************************************
|
|---|
| 285 | //******************************************************************************
|
|---|
| 286 | BOOL OSLibWinIsIconic(HWND hwnd)
|
|---|
| 287 | {
|
|---|
| 288 | SWP swp;
|
|---|
| 289 | BOOL rc;
|
|---|
| 290 |
|
|---|
| 291 | rc = WinQueryWindowPos(hwnd, &swp);
|
|---|
| 292 | if(rc == FALSE) {
|
|---|
| 293 | dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
|
|---|
| 294 | return FALSE;
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | if(swp.fl & SWP_MINIMIZE)
|
|---|
| 298 | return TRUE;
|
|---|
| 299 | else return FALSE;
|
|---|
| 300 | }
|
|---|
| 301 | //******************************************************************************
|
|---|
| 302 | //******************************************************************************
|
|---|
| 303 | BOOL OSLibWinSetActiveWindow(HWND hwnd)
|
|---|
| 304 | {
|
|---|
| 305 | return WinSetActiveWindow(HWND_DESKTOP, hwnd);
|
|---|
| 306 | }
|
|---|
| 307 | //******************************************************************************
|
|---|
| 308 | //******************************************************************************
|
|---|
| 309 | BOOL OSLibWinSetFocus(HWND hwnd)
|
|---|
| 310 | {
|
|---|
| 311 | return WinSetFocus(HWND_DESKTOP, hwnd);
|
|---|
| 312 | }
|
|---|
| 313 | //******************************************************************************
|
|---|
| 314 | //******************************************************************************
|
|---|
| 315 | BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
|
|---|
| 316 | {
|
|---|
| 317 | return WinEnableWindow(hwnd, fEnable);
|
|---|
| 318 | }
|
|---|
| 319 | //******************************************************************************
|
|---|
| 320 | //******************************************************************************
|
|---|
| 321 | BOOL OSLibWinIsWindowEnabled(HWND hwnd)
|
|---|
| 322 | {
|
|---|
| 323 | return WinIsWindowEnabled(hwnd);
|
|---|
| 324 | }
|
|---|
| 325 | //******************************************************************************
|
|---|
| 326 | //******************************************************************************
|
|---|
| 327 | BOOL OSLibWinIsWindowVisible(HWND hwnd)
|
|---|
| 328 | {
|
|---|
| 329 | return WinIsWindowVisible(hwnd);
|
|---|
| 330 | }
|
|---|
| 331 | //******************************************************************************
|
|---|
| 332 | //******************************************************************************
|
|---|
| 333 | BOOL OSLibWinQueryActiveWindow()
|
|---|
| 334 | {
|
|---|
| 335 | return WinQueryActiveWindow(HWND_DESKTOP);
|
|---|
| 336 | }
|
|---|
| 337 | //******************************************************************************
|
|---|
| 338 | //******************************************************************************
|
|---|
| 339 | LONG OSLibWinQueryWindowTextLength(HWND hwnd)
|
|---|
| 340 | {
|
|---|
| 341 | return WinQueryWindowTextLength(hwnd);
|
|---|
| 342 | }
|
|---|
| 343 | //******************************************************************************
|
|---|
| 344 | //******************************************************************************
|
|---|
| 345 | LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
|
|---|
| 346 | {
|
|---|
| 347 | return WinQueryWindowText(hwnd, length, lpsz);
|
|---|
| 348 | }
|
|---|
| 349 | //******************************************************************************
|
|---|
| 350 | //******************************************************************************
|
|---|
| 351 | BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
|
|---|
| 352 | {
|
|---|
| 353 | return WinSetWindowText(hwnd, lpsz);
|
|---|
| 354 | }
|
|---|
| 355 | //******************************************************************************
|
|---|
| 356 | //******************************************************************************
|
|---|
| 357 | BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
|
|---|
| 358 | {
|
|---|
| 359 | return WinFlashWindow(hwnd, fFlash);
|
|---|
| 360 | }
|
|---|
| 361 | //******************************************************************************
|
|---|
| 362 | //******************************************************************************
|
|---|
| 363 | HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
|
|---|
| 364 | {
|
|---|
| 365 | return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
|
|---|
| 366 | }
|
|---|
| 367 | //******************************************************************************
|
|---|
| 368 | //******************************************************************************
|
|---|
| 369 | BOOL OSLibWinMinimizeWindow(HWND hwnd)
|
|---|
| 370 | {
|
|---|
| 371 | return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
|
|---|
| 372 | }
|
|---|
| 373 | //******************************************************************************
|
|---|
| 374 | //******************************************************************************
|
|---|
| 375 | BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
|
|---|
| 376 | {
|
|---|
| 377 | pointl->x = 0;
|
|---|
| 378 | pointl->y = 0;
|
|---|
| 379 | return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
|
|---|
| 380 | }
|
|---|
| 381 | //******************************************************************************
|
|---|
| 382 | //******************************************************************************
|
|---|
| 383 | BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
|
|---|
| 384 | {
|
|---|
| 385 | return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIcon, 0);
|
|---|
| 386 | }
|
|---|
| 387 | //******************************************************************************
|
|---|
| 388 | //******************************************************************************
|
|---|
| 389 |
|
|---|