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

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

replaced os2.h includes by os2wrap.h

File size: 9.7 KB
Line 
1/* $Id: oslibres.cpp,v 1.10 2000-03-13 13:10:47 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//******************************************************************************
49HANDLE OSLibWinCreateIcon(PVOID iconbitmap)
50{
51 POINTERINFO pointerInfo = {0};
52 HBITMAP hbmColor, hbmMask;
53 BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)iconbitmap;
54 BITMAPFILEHEADER2 *bfhBW;
55 BITMAPFILEHEADER2 *bfhColor;
56 HPS hps;
57 HANDLE hIcon;
58
59 if(iconbitmap == NULL) {
60 dprintf(("OSLibWinCreateIcon iconbitmap == NULL!!"));
61 return 0;
62 }
63 if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
64 // search best icon for the current screen,
65 // TODO: maybe compare icon size with screen size.
66 // Some bugs with black/white Icons ?
67 BITMAPARRAYFILEHEADER2 *next, *found;
68 LONG bitcountScreen, bitcountIcon=-1, cxIcon=-1, cyIcon=-1;
69
70 HPS hps = WinGetPS(HWND_DESKTOP);
71 HDC hdc = GpiQueryDevice(hps);
72 DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, &bitcountScreen);
73 WinReleasePS(hps);
74
75 next = found = bafh;
76 while(TRUE)
77 {
78 bfhColor = (BITMAPFILEHEADER2 *)((char *)&next->bfh2 + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
79 if(bfhColor->bmp2.cBitCount <= bitcountScreen &&
80 bfhColor->bmp2.cBitCount > bitcountIcon ||
81 (bfhColor->bmp2.cBitCount == bitcountIcon &&
82 (cxIcon < bfhColor->bmp2.cx || cyIcon < bfhColor->bmp2.cy)))
83 {
84 found = next;
85 bitcountIcon = bfhColor->bmp2.cBitCount;
86 cxIcon = bfhColor->bmp2.cx;
87 cyIcon = bfhColor->bmp2.cy;
88 }
89 if(next->offNext != 0)
90 next = (BITMAPARRAYFILEHEADER2 *) ((char *)bafh + next->offNext);
91 else
92 break;
93 }
94 bfhBW = &found->bfh2;
95 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
96 }
97 else {//single icon
98 bfhBW = (BITMAPFILEHEADER2 *)iconbitmap;
99 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
100 bafh = (BITMAPARRAYFILEHEADER2 *)bfhBW; //for calculation bitmap offset
101 }
102 hps = WinGetScreenPS(HWND_DESKTOP);
103
104 hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
105 (char *)bafh + bfhColor->offBits,
106 (BITMAPINFO2 *)&bfhColor->bmp2);
107 if(hbmColor == GPI_ERROR) {
108 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
109 WinReleasePS(hps);
110 return 0;
111 }
112 hbmMask = GpiCreateBitmap(hps, &bfhBW->bmp2, CBM_INIT,
113 (char *)bafh + bfhBW->offBits,
114 (BITMAPINFO2 *)&bfhBW->bmp2);
115 if(hbmMask == GPI_ERROR) {
116 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap hbmMask failed!"));
117 GpiDeleteBitmap(hbmColor);
118 WinReleasePS(hps);
119 return 0;
120 }
121
122 pointerInfo.fPointer = FALSE; //icon
123 pointerInfo.xHotspot = bfhBW->xHotspot;
124 pointerInfo.yHotspot = bfhBW->yHotspot;
125 pointerInfo.hbmColor = hbmColor;
126 pointerInfo.hbmPointer = hbmMask;
127 hIcon = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
128 if(hIcon == NULL) {
129 dprintf(("OSLibWinCreateIcon: WinCreatePointerIndirect failed!"));
130 }
131 GpiDeleteBitmap(hbmMask);
132 GpiDeleteBitmap(hbmColor);
133 WinReleasePS(hps);
134 return hIcon;
135}
136//******************************************************************************
137//******************************************************************************
138HANDLE OSLibWinCreatePointer(PVOID cursorbitmap)
139{
140 POINTERINFO pointerInfo = {0};
141 HBITMAP hbmColor = 0, hbmMask = 0;
142 BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)cursorbitmap;
143 BITMAPFILEHEADER2 *bfh = (BITMAPFILEHEADER2 *)cursorbitmap, *bfhColor = 0;
144 HPS hps;
145 HANDLE hPointer;
146
147 if(cursorbitmap == NULL) {
148 dprintf(("OSLibWinCreatePointer cursorbitmap == NULL!!"));
149 return 0;
150 }
151 if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
152 bfh = &bafh->bfh2;
153 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
154 }
155 else {//single cursor
156 bfh = (BITMAPFILEHEADER2 *)cursorbitmap;
157 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
158 bafh = (BITMAPARRAYFILEHEADER2 *)bfh; //for calculation bitmap offset
159 }
160 //skip xor/and mask
161 hps = WinGetScreenPS(HWND_DESKTOP);
162 hbmMask = GpiCreateBitmap(hps, &bfh->bmp2, CBM_INIT,
163 (char *)bafh + bfh->offBits,
164 (BITMAPINFO2 *)&bfh->bmp2);
165 if(hbmMask == GPI_ERROR) {
166 dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
167 WinReleasePS(hps);
168 return 0;
169 }
170
171 if((ULONG)((char *)bafh+bfh->offBits) != (ULONG)bfhColor)
172 {//color bitmap present
173 hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
174 (char *)bafh + bfhColor->offBits,
175 (BITMAPINFO2 *)&bfhColor->bmp2);
176 if(hbmColor == GPI_ERROR) {
177 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
178 GpiDeleteBitmap(hbmMask);
179 WinReleasePS(hps);
180 return 0;
181 }
182 }
183
184 pointerInfo.fPointer = TRUE;
185 pointerInfo.xHotspot = bfh->xHotspot;
186 pointerInfo.yHotspot = bfh->yHotspot;
187 pointerInfo.hbmColor = hbmColor;
188 pointerInfo.hbmPointer = hbmMask;
189 hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
190
191 if(hPointer == NULL) {
192 dprintf(("OSLibWinCreatePointer: WinCreatePointerIndirect failed!"));
193 }
194 GpiDeleteBitmap(hbmMask);
195 if(hbmColor) GpiDeleteBitmap(hbmColor);
196 WinReleasePS(hps);
197 return hPointer;
198}
199//******************************************************************************
200//******************************************************************************
201HANDLE OSLibWinQuerySysIcon(ULONG type,INT w,INT h)
202{
203 ULONG os2type = 0;
204 HPOINTER hPointer;
205
206 switch(type) {
207 case IDI_APPLICATION_W:
208 os2type = SPTR_PROGRAM;
209 break;
210 case IDI_HAND_W:
211 os2type = SPTR_ICONWARNING;
212 break;
213 case IDI_QUESTION_W:
214 os2type = SPTR_ICONQUESTION;
215 break;
216 case IDI_EXCLAMATION_W:
217 os2type = SPTR_ICONWARNING;
218 break;
219 case IDI_ASTERISK_W:
220 os2type = SPTR_ICONINFORMATION;
221 break;
222 default:
223 return 0;
224 }
225
226 hPointer = WinQuerySysPointer(HWND_DESKTOP, os2type, TRUE);
227
228 if (hPointer)
229 {
230 INT sysW = WinQuerySysValue(HWND_DESKTOP,SV_CXICON),sysH = WinQuerySysValue(HWND_DESKTOP,SV_CYICON);
231
232 if (sysW != w || sysH != h)
233 {
234 POINTERINFO pi;
235
236 WinQueryPointerInfo(hPointer,&pi);
237 //CB: todo: change icon size
238
239 }
240 }
241
242 return hPointer;
243}
244//******************************************************************************
245//******************************************************************************
246HANDLE OSLibWinQuerySysPointer(ULONG type,INT w,INT h)
247{
248 ULONG os2type = 0;
249
250 switch(type) {
251 case IDC_ARROW_W:
252 os2type = SPTR_ARROW;
253 break;
254 case IDC_UPARROW_W:
255 os2type = SPTR_ARROW;
256 break;
257 case IDC_IBEAM_W:
258 os2type = SPTR_TEXT;
259 break;
260 case IDC_ICON_W:
261 os2type = SPTR_PROGRAM;
262 break;
263 case IDC_NO_W:
264 os2type = SPTR_ILLEGAL;
265 break;
266 case IDC_CROSS_W:
267 os2type = SPTR_MOVE;
268 break;
269 case IDC_SIZE_W:
270 os2type = SPTR_MOVE;
271 break;
272 case IDC_SIZEALL_W:
273 os2type = SPTR_MOVE;
274 break;
275 case IDC_SIZENESW_W:
276 os2type = SPTR_SIZENESW;
277 break;
278 case IDC_SIZENS_W:
279 os2type = SPTR_SIZENS;
280 break;
281 case IDC_SIZENWSE_W:
282 os2type = SPTR_SIZENWSE;
283 break;
284 case IDC_SIZEWE_W:
285 os2type = SPTR_SIZEWE;
286 break;
287 case IDC_WAIT_W:
288 os2type = SPTR_WAIT;
289 break;
290 case IDC_APPSTARTING_W:
291 os2type = SPTR_WAIT;
292 break;
293 case IDC_HELP_W: //TODO: Create a cursor for this one
294 os2type = SPTR_WAIT;
295 break;
296 default:
297 return 0;
298 }
299 //Note: Does not create a copy
300 return WinQuerySysPointer(HWND_DESKTOP, os2type, FALSE);
301}
302//******************************************************************************
303//******************************************************************************
Note: See TracBrowser for help on using the repository browser.