source: trunk/src/user32/oslibres.cpp@ 1474

Last change on this file since 1474 was 1474, checked in by sandervl, 26 years ago

Color cursor changes

File size: 9.2 KB
Line 
1/* $Id: oslibres.cpp,v 1.5 1999-10-27 10:35: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//******************************************************************************
30HANDLE 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//******************************************************************************
48HANDLE 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//******************************************************************************
137HANDLE OSLibWinCreatePointer(PVOID cursorbitmap)
138{
139 POINTERINFO pointerInfo = {0};
140 HBITMAP hbmColor = 0, hbmMask = 0;
141 BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)cursorbitmap;
142 BITMAPFILEHEADER2 *bfh = (BITMAPFILEHEADER2 *)cursorbitmap, *bfhColor = 0;
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 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
153 }
154 else {//single cursor
155 bfh = (BITMAPFILEHEADER2 *)cursorbitmap;
156 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
157 bafh = (BITMAPARRAYFILEHEADER2 *)bfh; //for calculation bitmap offset
158 }
159 //skip xor/and mask
160 hps = WinGetScreenPS(HWND_DESKTOP);
161 hbmMask = GpiCreateBitmap(hps, &bfh->bmp2, CBM_INIT,
162 (char *)bafh + bfh->offBits,
163 (BITMAPINFO2 *)&bfh->bmp2);
164 if(hbmMask == GPI_ERROR) {
165 dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
166 WinReleasePS(hps);
167 return 0;
168 }
169
170 if((ULONG)((char *)bafh+bfh->offBits) != (ULONG)bfhColor)
171 {//color bitmap present
172 hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
173 (char *)bafh + bfhColor->offBits,
174 (BITMAPINFO2 *)&bfhColor->bmp2);
175 if(hbmColor == GPI_ERROR) {
176 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
177 GpiDeleteBitmap(hbmMask);
178 WinReleasePS(hps);
179 return 0;
180 }
181 }
182
183 pointerInfo.fPointer = TRUE;
184 pointerInfo.xHotspot = bfh->xHotspot;
185 pointerInfo.yHotspot = bfh->yHotspot;
186 pointerInfo.hbmColor = hbmColor;
187 pointerInfo.hbmPointer = hbmMask;
188 hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
189
190 if(hPointer == NULL) {
191 dprintf(("OSLibWinCreatePointer: WinCreatePointerIndirect failed!"));
192 }
193 GpiDeleteBitmap(hbmMask);
194 if(hbmColor) GpiDeleteBitmap(hbmColor);
195 WinReleasePS(hps);
196 return hPointer;
197}
198//******************************************************************************
199//******************************************************************************
200HANDLE OSLibWinQuerySysIcon(ULONG type)
201{
202 ULONG os2type = 0;
203
204 switch(type) {
205 case IDI_APPLICATION_W:
206 os2type = SPTR_PROGRAM;
207 break;
208 case IDI_HAND_W:
209 os2type = SPTR_ICONWARNING;
210 break;
211 case IDI_QUESTION_W:
212 os2type = SPTR_ICONQUESTION;
213 break;
214 case IDI_EXCLAMATION_W:
215 os2type = SPTR_ICONWARNING;
216 break;
217 case IDI_ASTERISK_W:
218 os2type = SPTR_ICONINFORMATION;
219 break;
220 default:
221 return 0;
222 }
223
224 return WinQuerySysPointer(HWND_DESKTOP, os2type, TRUE);
225}
226//******************************************************************************
227//******************************************************************************
228HANDLE OSLibWinQuerySysPointer(ULONG type)
229{
230 ULONG os2type = 0;
231
232 switch(type) {
233 case IDC_ARROW_W:
234 os2type = SPTR_ARROW;
235 break;
236 case IDC_UPARROW_W:
237 os2type = SPTR_ARROW;
238 break;
239 case IDC_IBEAM_W:
240 os2type = SPTR_TEXT;
241 break;
242 case IDC_ICON_W:
243 os2type = SPTR_PROGRAM;
244 break;
245 case IDC_NO_W:
246 os2type = SPTR_ILLEGAL;
247 break;
248 case IDC_CROSS_W:
249 os2type = SPTR_MOVE;
250 break;
251 case IDC_SIZE_W:
252 os2type = SPTR_MOVE;
253 break;
254 case IDC_SIZEALL_W:
255 os2type = SPTR_MOVE;
256 break;
257 case IDC_SIZENESW_W:
258 os2type = SPTR_SIZENESW;
259 break;
260 case IDC_SIZENS_W:
261 os2type = SPTR_SIZENS;
262 break;
263 case IDC_SIZENWSE_W:
264 os2type = SPTR_SIZENWSE;
265 break;
266 case IDC_SIZEWE_W:
267 os2type = SPTR_SIZEWE;
268 break;
269 case IDC_WAIT_W:
270 os2type = SPTR_WAIT;
271 break;
272 case IDC_APPSTARTING_W:
273 os2type = SPTR_WAIT;
274 break;
275 case IDC_HELP_W: //TODO: Create a cursor for this one
276 os2type = SPTR_WAIT;
277 break;
278 default:
279 return 0;
280 }
281 //Note: Does not create a copy
282 return WinQuerySysPointer(HWND_DESKTOP, os2type, FALSE);
283}
284//******************************************************************************
285//******************************************************************************
Note: See TracBrowser for help on using the repository browser.