| 1 | /* $Id: oslibres.cpp,v 1.4 1999-09-25 14:16:05 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 | //******************************************************************************
|
|---|
| 30 | HANDLE OSLibWinSetAccelTable(HWND hwnd, HANDLE hAccel, PVOID acceltemplate)
|
|---|
| 31 | {
|
|---|
| 32 | HAB hab = WinQueryAnchorBlock(hwnd);
|
|---|
| 33 |
|
|---|
| 34 | if(hAccel == 0) {
|
|---|
| 35 | hAccel = WinCreateAccelTable(hab, (PACCELTABLE)acceltemplate);
|
|---|
| 36 | if(hAccel == 0) {
|
|---|
| 37 | dprintf(("OSLibWinSetAccelTable: WinCreateAccelTable returned 0"));
|
|---|
| 38 | return FALSE;
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 | if(WinSetAccelTable(hab, hAccel, hwnd) == TRUE) {
|
|---|
| 42 | return hAccel;
|
|---|
| 43 | }
|
|---|
| 44 | else return 0;
|
|---|
| 45 | }
|
|---|
| 46 | //******************************************************************************
|
|---|
| 47 | //******************************************************************************
|
|---|
| 48 | HANDLE OSLibWinCreateIcon(PVOID iconbitmap)
|
|---|
| 49 | {
|
|---|
| 50 | POINTERINFO pointerInfo = {0};
|
|---|
| 51 | HBITMAP hbmColor, hbmMask;
|
|---|
| 52 | BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)iconbitmap;
|
|---|
| 53 | BITMAPFILEHEADER2 *bfhBW;
|
|---|
| 54 | BITMAPFILEHEADER2 *bfhColor;
|
|---|
| 55 | HPS hps;
|
|---|
| 56 | HANDLE hIcon;
|
|---|
| 57 |
|
|---|
| 58 | if(iconbitmap == NULL) {
|
|---|
| 59 | dprintf(("OSLibWinCreateIcon iconbitmap == NULL!!"));
|
|---|
| 60 | return 0;
|
|---|
| 61 | }
|
|---|
| 62 | if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
|
|---|
| 63 | // search best icon for the current screen,
|
|---|
| 64 | // TODO: maybe compare icon size with screen size.
|
|---|
| 65 | // Some bugs with black/white Icons ?
|
|---|
| 66 | BITMAPARRAYFILEHEADER2 *next, *found;
|
|---|
| 67 | LONG bitcountScreen, bitcountIcon=-1, cxIcon=-1, cyIcon=-1;
|
|---|
| 68 |
|
|---|
| 69 | HPS hps = WinGetPS(HWND_DESKTOP);
|
|---|
| 70 | HDC hdc = GpiQueryDevice(hps);
|
|---|
| 71 | DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, &bitcountScreen);
|
|---|
| 72 | WinReleasePS(hps);
|
|---|
| 73 |
|
|---|
| 74 | next = found = bafh;
|
|---|
| 75 | while(TRUE)
|
|---|
| 76 | {
|
|---|
| 77 | bfhColor = (BITMAPFILEHEADER2 *)((char *)&next->bfh2 + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
|
|---|
| 78 | if(bfhColor->bmp2.cBitCount <= bitcountScreen &&
|
|---|
| 79 | bfhColor->bmp2.cBitCount > bitcountIcon ||
|
|---|
| 80 | (bfhColor->bmp2.cBitCount == bitcountIcon &&
|
|---|
| 81 | (cxIcon < bfhColor->bmp2.cx || cyIcon < bfhColor->bmp2.cy)))
|
|---|
| 82 | {
|
|---|
| 83 | found = next;
|
|---|
| 84 | bitcountIcon = bfhColor->bmp2.cBitCount;
|
|---|
| 85 | cxIcon = bfhColor->bmp2.cx;
|
|---|
| 86 | cyIcon = bfhColor->bmp2.cy;
|
|---|
| 87 | }
|
|---|
| 88 | if(next->offNext != 0)
|
|---|
| 89 | next = (BITMAPARRAYFILEHEADER2 *) ((char *)bafh + next->offNext);
|
|---|
| 90 | else
|
|---|
| 91 | break;
|
|---|
| 92 | }
|
|---|
| 93 | bfhBW = &found->bfh2;
|
|---|
| 94 | bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
|
|---|
| 95 | }
|
|---|
| 96 | else {//single icon
|
|---|
| 97 | bfhBW = (BITMAPFILEHEADER2 *)iconbitmap;
|
|---|
| 98 | bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
|
|---|
| 99 | bafh = (BITMAPARRAYFILEHEADER2 *)bfhBW; //for calculation bitmap offset
|
|---|
| 100 | }
|
|---|
| 101 | hps = WinGetScreenPS(HWND_DESKTOP);
|
|---|
| 102 |
|
|---|
| 103 | hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
|
|---|
| 104 | (char *)bafh + bfhColor->offBits,
|
|---|
| 105 | (BITMAPINFO2 *)&bfhColor->bmp2);
|
|---|
| 106 | if(hbmColor == GPI_ERROR) {
|
|---|
| 107 | dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
|
|---|
| 108 | WinReleasePS(hps);
|
|---|
| 109 | return 0;
|
|---|
| 110 | }
|
|---|
| 111 | hbmMask = GpiCreateBitmap(hps, &bfhBW->bmp2, CBM_INIT,
|
|---|
| 112 | (char *)bafh + bfhBW->offBits,
|
|---|
| 113 | (BITMAPINFO2 *)&bfhBW->bmp2);
|
|---|
| 114 | if(hbmMask == GPI_ERROR) {
|
|---|
| 115 | dprintf(("OSLibWinCreateIcon: GpiCreateBitmap hbmMask failed!"));
|
|---|
| 116 | GpiDeleteBitmap(hbmColor);
|
|---|
| 117 | WinReleasePS(hps);
|
|---|
| 118 | return 0;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | pointerInfo.fPointer = FALSE; //icon
|
|---|
| 122 | pointerInfo.xHotspot = bfhBW->xHotspot;
|
|---|
| 123 | pointerInfo.yHotspot = bfhBW->yHotspot;
|
|---|
| 124 | pointerInfo.hbmColor = hbmColor;
|
|---|
| 125 | pointerInfo.hbmPointer = hbmMask;
|
|---|
| 126 | hIcon = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
|
|---|
| 127 | if(hIcon == NULL) {
|
|---|
| 128 | dprintf(("OSLibWinCreateIcon: WinCreatePointerIndirect failed!"));
|
|---|
| 129 | }
|
|---|
| 130 | GpiDeleteBitmap(hbmMask);
|
|---|
| 131 | GpiDeleteBitmap(hbmColor);
|
|---|
| 132 | WinReleasePS(hps);
|
|---|
| 133 | return hIcon;
|
|---|
| 134 | }
|
|---|
| 135 | //******************************************************************************
|
|---|
| 136 | //******************************************************************************
|
|---|
| 137 | HANDLE OSLibWinCreatePointer(PVOID cursorbitmap)
|
|---|
| 138 | {
|
|---|
| 139 | POINTERINFO pointerInfo = {0};
|
|---|
| 140 | HBITMAP hbmColor;
|
|---|
| 141 | BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)cursorbitmap;
|
|---|
| 142 | BITMAPFILEHEADER2 *bfh = (BITMAPFILEHEADER2 *)cursorbitmap;
|
|---|
| 143 | HPS hps;
|
|---|
| 144 | HANDLE hPointer;
|
|---|
| 145 |
|
|---|
| 146 | if(cursorbitmap == NULL) {
|
|---|
| 147 | dprintf(("OSLibWinCreatePointer cursorbitmap == NULL!!"));
|
|---|
| 148 | return 0;
|
|---|
| 149 | }
|
|---|
| 150 | if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
|
|---|
| 151 | bfh = &bafh->bfh2;
|
|---|
| 152 | }
|
|---|
| 153 | else {//single icon
|
|---|
| 154 | bfh = (BITMAPFILEHEADER2 *)cursorbitmap;
|
|---|
| 155 | bafh = (BITMAPARRAYFILEHEADER2 *)bfh; //for calculation bitmap offset
|
|---|
| 156 | }
|
|---|
| 157 | //skip xor/and mask
|
|---|
| 158 | hps = WinGetScreenPS(HWND_DESKTOP);
|
|---|
| 159 | hbmColor = GpiCreateBitmap(hps, &bfh->bmp2, CBM_INIT,
|
|---|
| 160 | (char *)bafh + bfh->offBits,
|
|---|
| 161 | (BITMAPINFO2 *)&bfh->bmp2);
|
|---|
| 162 | if(hbmColor == GPI_ERROR) {
|
|---|
| 163 | dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
|
|---|
| 164 | WinReleasePS(hps);
|
|---|
| 165 | return 0;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | pointerInfo.fPointer = TRUE;
|
|---|
| 169 | pointerInfo.xHotspot = bfh->xHotspot;
|
|---|
| 170 | pointerInfo.yHotspot = bfh->yHotspot;
|
|---|
| 171 | pointerInfo.hbmColor = 0;
|
|---|
| 172 | pointerInfo.hbmPointer = hbmColor;
|
|---|
| 173 | hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
|
|---|
| 174 |
|
|---|
| 175 | if(hPointer == NULL) {
|
|---|
| 176 | dprintf(("OSLibWinCreatePointer: WinCreatePointerIndirect failed!"));
|
|---|
| 177 | }
|
|---|
| 178 | GpiDeleteBitmap(hbmColor);
|
|---|
| 179 | WinReleasePS(hps);
|
|---|
| 180 | return hPointer;
|
|---|
| 181 | }
|
|---|
| 182 | //******************************************************************************
|
|---|
| 183 | //******************************************************************************
|
|---|
| 184 | HANDLE OSLibWinQuerySysIcon(ULONG type)
|
|---|
| 185 | {
|
|---|
| 186 | ULONG os2type = 0;
|
|---|
| 187 |
|
|---|
| 188 | switch(type) {
|
|---|
| 189 | case IDI_APPLICATION_W:
|
|---|
| 190 | os2type = SPTR_PROGRAM;
|
|---|
| 191 | break;
|
|---|
| 192 | case IDI_HAND_W:
|
|---|
| 193 | os2type = SPTR_ICONWARNING;
|
|---|
| 194 | break;
|
|---|
| 195 | case IDI_QUESTION_W:
|
|---|
| 196 | os2type = SPTR_ICONQUESTION;
|
|---|
| 197 | break;
|
|---|
| 198 | case IDI_EXCLAMATION_W:
|
|---|
| 199 | os2type = SPTR_ICONWARNING;
|
|---|
| 200 | break;
|
|---|
| 201 | case IDI_ASTERISK_W:
|
|---|
| 202 | os2type = SPTR_ICONINFORMATION;
|
|---|
| 203 | break;
|
|---|
| 204 | default:
|
|---|
| 205 | return 0;
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | return WinQuerySysPointer(HWND_DESKTOP, os2type, TRUE);
|
|---|
| 209 | }
|
|---|
| 210 | //******************************************************************************
|
|---|
| 211 | //******************************************************************************
|
|---|
| 212 | HANDLE OSLibWinQuerySysPointer(ULONG type)
|
|---|
| 213 | {
|
|---|
| 214 | ULONG os2type = 0;
|
|---|
| 215 |
|
|---|
| 216 | switch(type) {
|
|---|
| 217 | case IDC_ARROW_W:
|
|---|
| 218 | os2type = SPTR_ARROW;
|
|---|
| 219 | break;
|
|---|
| 220 | case IDC_UPARROW_W:
|
|---|
| 221 | os2type = SPTR_ARROW;
|
|---|
| 222 | break;
|
|---|
| 223 | case IDC_IBEAM_W:
|
|---|
| 224 | os2type = SPTR_TEXT;
|
|---|
| 225 | break;
|
|---|
| 226 | case IDC_ICON_W:
|
|---|
| 227 | os2type = SPTR_PROGRAM;
|
|---|
| 228 | break;
|
|---|
| 229 | case IDC_NO_W:
|
|---|
| 230 | os2type = SPTR_ILLEGAL;
|
|---|
| 231 | break;
|
|---|
| 232 | case IDC_CROSS_W:
|
|---|
| 233 | os2type = SPTR_MOVE;
|
|---|
| 234 | break;
|
|---|
| 235 | case IDC_SIZE_W:
|
|---|
| 236 | os2type = SPTR_MOVE;
|
|---|
| 237 | break;
|
|---|
| 238 | case IDC_SIZEALL_W:
|
|---|
| 239 | os2type = SPTR_MOVE;
|
|---|
| 240 | break;
|
|---|
| 241 | case IDC_SIZENESW_W:
|
|---|
| 242 | os2type = SPTR_SIZENESW;
|
|---|
| 243 | break;
|
|---|
| 244 | case IDC_SIZENS_W:
|
|---|
| 245 | os2type = SPTR_SIZENS;
|
|---|
| 246 | break;
|
|---|
| 247 | case IDC_SIZENWSE_W:
|
|---|
| 248 | os2type = SPTR_SIZENWSE;
|
|---|
| 249 | break;
|
|---|
| 250 | case IDC_SIZEWE_W:
|
|---|
| 251 | os2type = SPTR_SIZEWE;
|
|---|
| 252 | break;
|
|---|
| 253 | case IDC_WAIT_W:
|
|---|
| 254 | os2type = SPTR_WAIT;
|
|---|
| 255 | break;
|
|---|
| 256 | case IDC_APPSTARTING_W:
|
|---|
| 257 | os2type = SPTR_WAIT;
|
|---|
| 258 | break;
|
|---|
| 259 | case IDC_HELP_W: //TODO: Create a cursor for this one
|
|---|
| 260 | os2type = SPTR_WAIT;
|
|---|
| 261 | break;
|
|---|
| 262 | default:
|
|---|
| 263 | return 0;
|
|---|
| 264 | }
|
|---|
| 265 | //Note: Does not create a copy
|
|---|
| 266 | return WinQuerySysPointer(HWND_DESKTOP, os2type, FALSE);
|
|---|
| 267 | }
|
|---|
| 268 | //******************************************************************************
|
|---|
| 269 | //******************************************************************************
|
|---|