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

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

Edgar Buerkle's fixes for GetDesktopWindow, icons + WM_TIMER support

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