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

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

* empty log message *

File size: 9.6 KB
Line 
1/* $Id: oslibres.cpp,v 1.8 2000-01-18 20:10:41 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,INT w,INT h)
201{
202 ULONG os2type = 0;
203 HPOINTER hPointer;
204
205 switch(type) {
206 case IDI_APPLICATION_W:
207 os2type = SPTR_PROGRAM;
208 break;
209 case IDI_HAND_W:
210 os2type = SPTR_ICONWARNING;
211 break;
212 case IDI_QUESTION_W:
213 os2type = SPTR_ICONQUESTION;
214 break;
215 case IDI_EXCLAMATION_W:
216 os2type = SPTR_ICONWARNING;
217 break;
218 case IDI_ASTERISK_W:
219 os2type = SPTR_ICONINFORMATION;
220 break;
221 default:
222 return 0;
223 }
224
225 hPointer = WinQuerySysPointer(HWND_DESKTOP, os2type, TRUE);
226
227 if (hPointer)
228 {
229 INT sysW = WinQuerySysValue(HWND_DESKTOP,SV_CXICON),sysH = WinQuerySysValue(HWND_DESKTOP,SV_CYICON);
230
231 if (sysW != w || sysH != h)
232 {
233 POINTERINFO pi;
234
235 WinQueryPointerInfo(hPointer,&pi);
236 //CB: todo: change icon size
237
238 }
239 }
240
241 return hPointer;
242}
243//******************************************************************************
244//******************************************************************************
245HANDLE OSLibWinQuerySysPointer(ULONG type,INT w,INT h)
246{
247 ULONG os2type = 0;
248
249 switch(type) {
250 case IDC_ARROW_W:
251 os2type = SPTR_ARROW;
252 break;
253 case IDC_UPARROW_W:
254 os2type = SPTR_ARROW;
255 break;
256 case IDC_IBEAM_W:
257 os2type = SPTR_TEXT;
258 break;
259 case IDC_ICON_W:
260 os2type = SPTR_PROGRAM;
261 break;
262 case IDC_NO_W:
263 os2type = SPTR_ILLEGAL;
264 break;
265 case IDC_CROSS_W:
266 os2type = SPTR_MOVE;
267 break;
268 case IDC_SIZE_W:
269 os2type = SPTR_MOVE;
270 break;
271 case IDC_SIZEALL_W:
272 os2type = SPTR_MOVE;
273 break;
274 case IDC_SIZENESW_W:
275 os2type = SPTR_SIZENESW;
276 break;
277 case IDC_SIZENS_W:
278 os2type = SPTR_SIZENS;
279 break;
280 case IDC_SIZENWSE_W:
281 os2type = SPTR_SIZENWSE;
282 break;
283 case IDC_SIZEWE_W:
284 os2type = SPTR_SIZEWE;
285 break;
286 case IDC_WAIT_W:
287 os2type = SPTR_WAIT;
288 break;
289 case IDC_APPSTARTING_W:
290 os2type = SPTR_WAIT;
291 break;
292 case IDC_HELP_W: //TODO: Create a cursor for this one
293 os2type = SPTR_WAIT;
294 break;
295 default:
296 return 0;
297 }
298 //Note: Does not create a copy
299 return WinQuerySysPointer(HWND_DESKTOP, os2type, FALSE);
300}
301//******************************************************************************
302//******************************************************************************
Note: See TracBrowser for help on using the repository browser.