1 | /*
|
---|
2 | * PE2LX cursor conversion code
|
---|
3 | *
|
---|
4 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | *
|
---|
9 | */
|
---|
10 | #define INCL_GPIBITMAPS
|
---|
11 | #define INCL_BITMAPFILEFORMAT
|
---|
12 | #define INCL_DOSFILEMGR /* File Manager values */
|
---|
13 | #define INCL_DOSERRORS /* DOS Error values */
|
---|
14 | #define INCL_DOSPROCESS /* DOS Process values */
|
---|
15 | #define INCL_DOSMISC /* DOS Miscellanous values */
|
---|
16 | #define INCL_WIN
|
---|
17 | #include <os2.h>
|
---|
18 | #include <stdio.h>
|
---|
19 | #include <string.h>
|
---|
20 | #include <stdlib.h>
|
---|
21 | #include <iostream.h>
|
---|
22 | #include <string.h>
|
---|
23 | #include "pefile.h"
|
---|
24 | #include "lx.h"
|
---|
25 | #include "icon.h"
|
---|
26 | #include "cursor.h"
|
---|
27 | #include "misc.h"
|
---|
28 |
|
---|
29 |
|
---|
30 | //******************************************************************************
|
---|
31 | //******************************************************************************
|
---|
32 | OS2Cursor::OS2Cursor(int id,
|
---|
33 | CursorComponent *curHdr,
|
---|
34 | int size)
|
---|
35 | : id(0),
|
---|
36 | next(NULL),
|
---|
37 | cursorhdr(NULL),
|
---|
38 | cursorsize(0),
|
---|
39 | prevoffset(0)
|
---|
40 | {
|
---|
41 | OS2Cursor *cursor = OS2Cursor::cursors;
|
---|
42 | RGBQUAD *rgb;
|
---|
43 | RGB *os2rgb;
|
---|
44 | WINBITMAPINFOHEADER *bhdr = (WINBITMAPINFOHEADER *)(curHdr+1);
|
---|
45 | int i, bwsize, bmpsize;
|
---|
46 |
|
---|
47 | if(cursor != NULL)
|
---|
48 | {
|
---|
49 | while(cursor->next != NULL)
|
---|
50 | {
|
---|
51 | cursor = cursor->next;
|
---|
52 | }
|
---|
53 | cursor->next = this;
|
---|
54 | }
|
---|
55 | else
|
---|
56 | cursors = this;
|
---|
57 |
|
---|
58 | this->id = id;
|
---|
59 |
|
---|
60 | cout << "Cursor with id " << id << endl;
|
---|
61 | cout << "Cursor size " << size << endl;
|
---|
62 | bmpsize = size - sizeof(CursorComponent) - (1<<bhdr->biBitCount)*sizeof(RGBQUAD);
|
---|
63 | cursorsize = sizeof(BITMAPFILEHEADER) + bmpsize + (1<<bhdr->biBitCount)*sizeof(RGB);
|
---|
64 |
|
---|
65 | cursorhdr = (BITMAPFILEHEADER *)malloc(cursorsize);
|
---|
66 | cursorhdr->usType = BFT_POINTER;
|
---|
67 | cursorhdr->cbSize = sizeof(BITMAPFILEHEADER);
|
---|
68 | cursorhdr->xHotspot = curHdr->xHotspot;
|
---|
69 |
|
---|
70 | /* @@@PH y-hotspot is upside down ! */
|
---|
71 | cursorhdr->yHotspot = (bhdr->biHeight >> 1) - 1 /* height div 2 */
|
---|
72 | - curHdr->yHotspot; /* subtract hot.y */
|
---|
73 |
|
---|
74 | cout << "Cursor Hot.x : " << curHdr->xHotspot << endl;
|
---|
75 | cout << "Cursor Hot.y : " << curHdr->yHotspot << endl;
|
---|
76 |
|
---|
77 | cursorhdr->offBits = sizeof(BITMAPFILEHEADER) + 2*sizeof(RGB);
|
---|
78 | cursorhdr->bmp.cbFix = sizeof(BITMAPINFOHEADER);
|
---|
79 | cursorhdr->bmp.cx = (USHORT)bhdr->biWidth;
|
---|
80 | cursorhdr->bmp.cy = (USHORT)(bhdr->biHeight);
|
---|
81 | cursorhdr->bmp.cPlanes = bhdr->biPlanes;
|
---|
82 | cursorhdr->bmp.cBitCount = bhdr->biBitCount;
|
---|
83 | cout << "Cursor size : " << bhdr->biSizeImage << endl;
|
---|
84 | cout << "Cursor Width : " << bhdr->biWidth << endl;
|
---|
85 | //height for both the XOR and AND bitmap (color & BW)
|
---|
86 | cout << "Height : " << bhdr->biHeight << endl;
|
---|
87 | cout << "Cursor Bitcount: " << bhdr->biBitCount << endl;
|
---|
88 | cout << "Cursor Compress: " << bhdr->biCompression << endl;
|
---|
89 |
|
---|
90 | os2rgb = (RGB *)(cursorhdr+1);
|
---|
91 | rgb = (RGBQUAD *)(bhdr+1);
|
---|
92 | for(i=0;i<(1<<bhdr->biBitCount);i++) {
|
---|
93 | os2rgb->bRed = rgb->red;
|
---|
94 | os2rgb->bBlue = rgb->blue;
|
---|
95 | os2rgb->bGreen = rgb->green;
|
---|
96 | os2rgb++;
|
---|
97 | rgb++;
|
---|
98 | }
|
---|
99 |
|
---|
100 | if(bhdr->biSizeImage > bmpsize || bhdr->biSizeImage == 0) {
|
---|
101 | bwsize = bhdr->biWidth*(bhdr->biHeight);
|
---|
102 |
|
---|
103 | switch(bhdr->biBitCount) {
|
---|
104 | case 1:
|
---|
105 | bwsize /= 8;
|
---|
106 | break;
|
---|
107 | case 4:
|
---|
108 | bwsize /= 2;
|
---|
109 | break;
|
---|
110 | case 8:
|
---|
111 | break;
|
---|
112 | case 16:
|
---|
113 | bwsize *= 2;
|
---|
114 | break;
|
---|
115 | case 24:
|
---|
116 | bwsize *= 3;
|
---|
117 | break;
|
---|
118 | case 32:
|
---|
119 | bwsize *= 4;
|
---|
120 | break;
|
---|
121 | }
|
---|
122 | }
|
---|
123 | else bwsize = bhdr->biSizeImage;
|
---|
124 |
|
---|
125 | //write XOR and AND mask
|
---|
126 | memcpy((char *)os2rgb, (char *)rgb, bwsize);
|
---|
127 | }
|
---|
128 | //******************************************************************************
|
---|
129 | //******************************************************************************
|
---|
130 | void OS2Cursor::SetCursorHdrOffset(int offset)
|
---|
131 | {
|
---|
132 | cursorhdr->offBits += offset - prevoffset;
|
---|
133 | //remember in case cursors are used in multiple groups
|
---|
134 | //(can't imagine this ever happening, but you never know)
|
---|
135 | prevoffset = offset;
|
---|
136 | }
|
---|
137 | //******************************************************************************
|
---|
138 | //******************************************************************************
|
---|
139 | OS2Cursor::~OS2Cursor()
|
---|
140 | {
|
---|
141 | if(cursorhdr) free(cursorhdr);
|
---|
142 | }
|
---|
143 | //******************************************************************************
|
---|
144 | //******************************************************************************
|
---|
145 | int OS2Cursor::QueryCursorSize()
|
---|
146 | {
|
---|
147 | return(cursorsize);
|
---|
148 | }
|
---|
149 | //******************************************************************************
|
---|
150 | //******************************************************************************
|
---|
151 | #ifdef __WATCOMC__
|
---|
152 | #pragma off (unreferenced)
|
---|
153 | #endif
|
---|
154 | BITMAPFILEHEADER *OS2Cursor::GetCursorHeader(int wWidth, int wHeight, int wPlanes, int wBitCount)
|
---|
155 | #ifdef __WATCOMC__
|
---|
156 | #pragma on (unreferenced)
|
---|
157 | #endif
|
---|
158 | {
|
---|
159 | //SvL: 20-11-'97: already filled in
|
---|
160 | #if 0
|
---|
161 | cursorhdr->bmp.cx = wWidth;
|
---|
162 | cursorhdr->bmp.cy = wHeight;
|
---|
163 | cursorhdr->bmp.cPlanes = wPlanes;
|
---|
164 | cursorhdr->bmp.cBitCount = wBitCount;
|
---|
165 | #endif
|
---|
166 | return(cursorhdr);
|
---|
167 | }
|
---|
168 | //******************************************************************************
|
---|
169 | //******************************************************************************
|
---|
170 | OS2Cursor *OS2Cursor::GetCursor(int id)
|
---|
171 | {
|
---|
172 | OS2Cursor *cursor = OS2Cursor::cursors;
|
---|
173 |
|
---|
174 | while(cursor != NULL) {
|
---|
175 | if(cursor->id == id) {
|
---|
176 | return(cursor);
|
---|
177 | }
|
---|
178 | cursor = cursor->next;
|
---|
179 | }
|
---|
180 | return(NULL);
|
---|
181 | }
|
---|
182 | //******************************************************************************
|
---|
183 | //******************************************************************************
|
---|
184 | void OS2Cursor::DestroyAll()
|
---|
185 | {
|
---|
186 | OS2Cursor *cursor = OS2Cursor::cursors, *next;
|
---|
187 |
|
---|
188 | while(cursor != NULL) {
|
---|
189 | next = cursor->next;
|
---|
190 | delete(cursor);
|
---|
191 | cursor = next;
|
---|
192 | }
|
---|
193 | }
|
---|
194 | //******************************************************************************
|
---|
195 | //******************************************************************************
|
---|
196 | OS2Cursor *OS2Cursor::cursors = NULL;
|
---|