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

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

Cursor fixes

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