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

Last change on this file since 4573 was 4573, checked in by sandervl, 25 years ago

Icon api rewrite + small fixes

File size: 10.9 KB
Line 
1/* $Id: oslibres.cpp,v 1.11 2000-11-09 18:15:18 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 <os2wrap.h>
15#include <stdlib.h>
16#include <string.h>
17
18#include <misc.h>
19#include <winconst.h>
20#include "oslibwin.h"
21#include "oslibutil.h"
22#include "oslibmsg.h"
23#include "oslibgdi.h"
24#include "pmwindow.h"
25
26#define DBG_LOCALLOG DBG_oslibres
27#include "dbglocal.h"
28
29//******************************************************************************
30//******************************************************************************
31HANDLE OSLibWinSetAccelTable(HWND hwnd, HANDLE hAccel, PVOID acceltemplate)
32{
33 HAB hab = WinQueryAnchorBlock(hwnd);
34
35 if(hAccel == 0) {
36 hAccel = WinCreateAccelTable(hab, (PACCELTABLE)acceltemplate);
37 if(hAccel == 0) {
38 dprintf(("OSLibWinSetAccelTable: WinCreateAccelTable returned 0"));
39 return FALSE;
40 }
41 }
42 if(WinSetAccelTable(hab, hAccel, hwnd) == TRUE) {
43 return hAccel;
44 }
45 else return 0;
46}
47//******************************************************************************
48//TODO: change search method for icon array (cxDesired, cyDesired)
49//TODO: PM rescales the icon internally!!! ($W(#*&$(*%&)
50//******************************************************************************
51HANDLE OSLibWinCreateIcon(PVOID iconbitmap, ULONG cxDesired, ULONG cyDesired)
52{
53 POINTERINFO pointerInfo = {0};
54 HBITMAP hbmColor, hbmMask;
55 BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)iconbitmap;
56 BITMAPFILEHEADER2 *bfhBW;
57 BITMAPFILEHEADER2 *bfhColor;
58 HPS hps;
59 HANDLE hIcon;
60
61 if(iconbitmap == NULL) {
62 dprintf(("OSLibWinCreateIcon iconbitmap == NULL!!"));
63 return 0;
64 }
65 if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
66 // search best icon for the current screen,
67 // TODO: maybe compare icon size with screen size.
68 // Some bugs with black/white Icons ?
69 BITMAPARRAYFILEHEADER2 *next, *found;
70 LONG bitcountScreen, bitcountIcon=-1, cxIcon=-1, cyIcon=-1;
71
72 HPS hps = WinGetPS(HWND_DESKTOP);
73 HDC hdc = GpiQueryDevice(hps);
74 DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, &bitcountScreen);
75 WinReleasePS(hps);
76
77 next = found = bafh;
78 while(TRUE)
79 {
80 bfhColor = (BITMAPFILEHEADER2 *)((char *)&next->bfh2 + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
81 if(bfhColor->bmp2.cBitCount <= bitcountScreen &&
82 bfhColor->bmp2.cBitCount > bitcountIcon ||
83 (bfhColor->bmp2.cBitCount == bitcountIcon &&
84 (cxIcon < bfhColor->bmp2.cx || cyIcon < bfhColor->bmp2.cy)))
85 {
86 found = next;
87 bitcountIcon = bfhColor->bmp2.cBitCount;
88 cxIcon = bfhColor->bmp2.cx;
89 cyIcon = bfhColor->bmp2.cy;
90 }
91 if(next->offNext != 0)
92 next = (BITMAPARRAYFILEHEADER2 *) ((char *)bafh + next->offNext);
93 else
94 break;
95 }
96 bfhBW = &found->bfh2;
97 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
98 }
99 else {//single icon
100 bfhBW = (BITMAPFILEHEADER2 *)iconbitmap;
101 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
102 bafh = (BITMAPARRAYFILEHEADER2 *)bfhBW; //for calculation bitmap offset
103 }
104 hps = WinGetScreenPS(HWND_DESKTOP);
105
106 //Resize icon bitmap if requested size is different
107 if(cxDesired != bfhColor->bmp2.cx|| cyDesired != bfhColor->bmp2.cy)
108 {
109 BITMAPINFOHEADER2 infohdr = bfhColor->bmp2;
110
111 infohdr.cx = cxDesired;
112 infohdr.cy = cyDesired;
113 hbmColor = GpiCreateBitmap(hps, &infohdr, CBM_INIT,
114 (char *)bafh + bfhColor->offBits,
115 (BITMAPINFO2 *)&bfhColor->bmp2);
116 }
117 else {
118 hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
119 (char *)bafh + bfhColor->offBits,
120 (BITMAPINFO2 *)&bfhColor->bmp2);
121 }
122 if(hbmColor == GPI_ERROR) {
123 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
124 WinReleasePS(hps);
125 return 0;
126 }
127 //Resize icon mask if requested size is different
128 if(cxDesired != bfhBW->bmp2.cx|| cyDesired*2 != bfhBW->bmp2.cy)
129 {
130 BITMAPINFOHEADER2 infohdr = bfhBW->bmp2;
131
132 infohdr.cx = cxDesired;
133 infohdr.cy = cyDesired;
134 hbmMask = GpiCreateBitmap(hps, &infohdr, CBM_INIT,
135 (char *)bafh + bfhBW->offBits,
136 (BITMAPINFO2 *)&bfhBW->bmp2);
137 }
138 else {
139 hbmMask = GpiCreateBitmap(hps, &bfhBW->bmp2, CBM_INIT,
140 (char *)bafh + bfhBW->offBits,
141 (BITMAPINFO2 *)&bfhBW->bmp2);
142 }
143 if(hbmMask == GPI_ERROR) {
144 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap hbmMask failed!"));
145 GpiDeleteBitmap(hbmColor);
146 WinReleasePS(hps);
147 return 0;
148 }
149
150 pointerInfo.fPointer = FALSE; //icon
151 pointerInfo.xHotspot = bfhBW->xHotspot;
152 pointerInfo.yHotspot = bfhBW->yHotspot;
153 pointerInfo.hbmColor = hbmColor;
154 pointerInfo.hbmPointer = hbmMask;
155 hIcon = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
156 if(hIcon == NULL) {
157 dprintf(("OSLibWinCreateIcon: WinCreatePointerIndirect failed!"));
158 }
159 GpiDeleteBitmap(hbmMask);
160 GpiDeleteBitmap(hbmColor);
161 WinReleasePS(hps);
162
163 return hIcon;
164}
165//******************************************************************************
166//TODO: change cursor size if required!! (cxDesired, cyDesired)
167//******************************************************************************
168HANDLE OSLibWinCreatePointer(PVOID cursorbitmap, ULONG cxDesired, ULONG cyDesired)
169{
170 POINTERINFO pointerInfo = {0};
171 HBITMAP hbmColor = 0, hbmMask = 0;
172 BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)cursorbitmap;
173 BITMAPFILEHEADER2 *bfh = (BITMAPFILEHEADER2 *)cursorbitmap, *bfhColor = 0;
174 HPS hps;
175 HANDLE hPointer;
176
177 if(cursorbitmap == NULL) {
178 dprintf(("OSLibWinCreatePointer cursorbitmap == NULL!!"));
179 return 0;
180 }
181 if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
182 bfh = &bafh->bfh2;
183 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
184 }
185 else {//single cursor
186 bfh = (BITMAPFILEHEADER2 *)cursorbitmap;
187 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
188 bafh = (BITMAPARRAYFILEHEADER2 *)bfh; //for calculation bitmap offset
189 }
190 //skip xor/and mask
191 hps = WinGetScreenPS(HWND_DESKTOP);
192 hbmMask = GpiCreateBitmap(hps, &bfh->bmp2, CBM_INIT,
193 (char *)bafh + bfh->offBits,
194 (BITMAPINFO2 *)&bfh->bmp2);
195 if(hbmMask == GPI_ERROR) {
196 dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
197 WinReleasePS(hps);
198 return 0;
199 }
200
201 if((ULONG)((char *)bafh+bfh->offBits) != (ULONG)bfhColor)
202 {//color bitmap present
203 hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
204 (char *)bafh + bfhColor->offBits,
205 (BITMAPINFO2 *)&bfhColor->bmp2);
206 if(hbmColor == GPI_ERROR) {
207 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
208 GpiDeleteBitmap(hbmMask);
209 WinReleasePS(hps);
210 return 0;
211 }
212 }
213
214 pointerInfo.fPointer = TRUE;
215 pointerInfo.xHotspot = bfh->xHotspot;
216 pointerInfo.yHotspot = bfh->yHotspot;
217 pointerInfo.hbmColor = hbmColor;
218 pointerInfo.hbmPointer = hbmMask;
219 hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
220
221 if(hPointer == NULL) {
222 dprintf(("OSLibWinCreatePointer: WinCreatePointerIndirect failed!"));
223 }
224 GpiDeleteBitmap(hbmMask);
225 if(hbmColor) GpiDeleteBitmap(hbmColor);
226 WinReleasePS(hps);
227 return hPointer;
228}
229//******************************************************************************
230//******************************************************************************
231HANDLE OSLibWinQuerySysIcon(ULONG type,INT w,INT h)
232{
233 ULONG os2type = 0;
234 HPOINTER hPointer;
235
236 switch(type) {
237 case IDI_APPLICATION_W:
238 os2type = SPTR_PROGRAM;
239 break;
240 case IDI_HAND_W:
241 os2type = SPTR_ICONWARNING;
242 break;
243 case IDI_QUESTION_W:
244 os2type = SPTR_ICONQUESTION;
245 break;
246 case IDI_EXCLAMATION_W:
247 os2type = SPTR_ICONWARNING;
248 break;
249 case IDI_ASTERISK_W:
250 os2type = SPTR_ICONINFORMATION;
251 break;
252 default:
253 return 0;
254 }
255
256 hPointer = WinQuerySysPointer(HWND_DESKTOP, os2type, TRUE);
257
258 if (hPointer)
259 {
260 INT sysW = WinQuerySysValue(HWND_DESKTOP,SV_CXICON),sysH = WinQuerySysValue(HWND_DESKTOP,SV_CYICON);
261
262 if (sysW != w || sysH != h)
263 {
264 POINTERINFO pi;
265
266 WinQueryPointerInfo(hPointer,&pi);
267 //CB: todo: change icon size
268
269 }
270 }
271
272 return hPointer;
273}
274//******************************************************************************
275//******************************************************************************
276HANDLE OSLibWinQuerySysPointer(ULONG type,INT w,INT h)
277{
278 ULONG os2type = 0;
279
280 switch(type) {
281 case IDC_ARROW_W:
282 os2type = SPTR_ARROW;
283 break;
284 case IDC_UPARROW_W:
285 os2type = SPTR_ARROW;
286 break;
287 case IDC_IBEAM_W:
288 os2type = SPTR_TEXT;
289 break;
290 case IDC_ICON_W:
291 os2type = SPTR_PROGRAM;
292 break;
293 case IDC_NO_W:
294 os2type = SPTR_ILLEGAL;
295 break;
296 case IDC_CROSS_W:
297 os2type = SPTR_MOVE;
298 break;
299 case IDC_SIZE_W:
300 os2type = SPTR_MOVE;
301 break;
302 case IDC_SIZEALL_W:
303 os2type = SPTR_MOVE;
304 break;
305 case IDC_SIZENESW_W:
306 os2type = SPTR_SIZENESW;
307 break;
308 case IDC_SIZENS_W:
309 os2type = SPTR_SIZENS;
310 break;
311 case IDC_SIZENWSE_W:
312 os2type = SPTR_SIZENWSE;
313 break;
314 case IDC_SIZEWE_W:
315 os2type = SPTR_SIZEWE;
316 break;
317 case IDC_WAIT_W:
318 os2type = SPTR_WAIT;
319 break;
320 case IDC_APPSTARTING_W:
321 os2type = SPTR_WAIT;
322 break;
323 case IDC_HELP_W: //TODO: Create a cursor for this one
324 os2type = SPTR_WAIT;
325 break;
326 default:
327 return 0;
328 }
329 //Note: Does not create a copy
330 return WinQuerySysPointer(HWND_DESKTOP, os2type, FALSE);
331}
332//******************************************************************************
333//******************************************************************************
Note: See TracBrowser for help on using the repository browser.