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

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

Added new logging feature

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