1 | /* $Id: winres.cpp,v 1.23 1999-12-07 12:28:41 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 resource class
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | *
|
---|
12 | */
|
---|
13 | #define INCL_BASE
|
---|
14 | #define INCL_WIN
|
---|
15 | #define INCL_GPIBITMAPS
|
---|
16 | #define INCL_BITMAPFILEFORMAT
|
---|
17 | #define INCL_DOSMODULEMGR
|
---|
18 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
19 | #include <stdarg.h>
|
---|
20 | #ifdef __IBMCPP__
|
---|
21 | #include <builtin.h>
|
---|
22 | #endif
|
---|
23 | #include <stdio.h>
|
---|
24 | #include <stdlib.h>
|
---|
25 | #include <string.h>
|
---|
26 | #define INCL_WINRES
|
---|
27 | #include <win32type.h>
|
---|
28 | #include <winres.h>
|
---|
29 | #include <misc.h>
|
---|
30 | #include <winexepe2lx.h>
|
---|
31 | #include <windllpe2lx.h>
|
---|
32 | #include "cvtresource.h"
|
---|
33 | #include <vmutex.h>
|
---|
34 |
|
---|
35 | VMutex resmutex;
|
---|
36 |
|
---|
37 | char *ResTypes[MAX_RES] =
|
---|
38 | {"niks", "CURSOR", "BITMAP", "ICON", "MENU", "DIALOG", "STRING",
|
---|
39 | "FONTDIR", "FONT", "ACCELERATOR", "RCDATA", "MESSAGETABLE",
|
---|
40 | "GROUP_CURSOR", "niks", "GROUP_ICON", "niks", "VERSION"};
|
---|
41 |
|
---|
42 | //******************************************************************************
|
---|
43 | //******************************************************************************
|
---|
44 | Win32Resource::Win32Resource() :
|
---|
45 | os2resdata(NULL), winresdata(NULL), resType(RSRC_CUSTOMNODATA)
|
---|
46 | {
|
---|
47 | next = NULL;
|
---|
48 | module = NULL;
|
---|
49 |
|
---|
50 | id = -1;
|
---|
51 | type = -1;
|
---|
52 | hres = 0;
|
---|
53 | OS2ResHandle = 0;
|
---|
54 | //resources are in Unicode format by default; indirectly created resources
|
---|
55 | //can also be in ascii format
|
---|
56 | isUnicode = TRUE;
|
---|
57 | }
|
---|
58 | //******************************************************************************
|
---|
59 | //******************************************************************************
|
---|
60 | Win32Resource::Win32Resource(Win32ImageBase *module, ULONG id, ULONG type,
|
---|
61 | ULONG size, char *resdata) : hres(NULL),
|
---|
62 | os2resdata(NULL), winresdata(NULL), resType(RSRC_PELOADER)
|
---|
63 | {
|
---|
64 | resmutex.enter();
|
---|
65 | next = module->winres;
|
---|
66 | module->winres = this;
|
---|
67 | resmutex.leave();
|
---|
68 |
|
---|
69 | this->module = module;
|
---|
70 | this->id = id;
|
---|
71 | this->type = type;
|
---|
72 | this->ressize = size;
|
---|
73 | winresdata = (char *)malloc(size+sizeof(WCHAR)); //+2 for 0 terminator (string res)
|
---|
74 | if(winresdata == NULL) {
|
---|
75 | DebugInt3();
|
---|
76 | return;
|
---|
77 | }
|
---|
78 | OS2ResHandle = 0;
|
---|
79 |
|
---|
80 | if(type == NTRT_STRING) {
|
---|
81 | memcpy(winresdata, resdata, size);
|
---|
82 | ((USHORT *)winresdata)[size/sizeof(WCHAR)] = 0;
|
---|
83 | }
|
---|
84 | else memcpy(winresdata, resdata, size);
|
---|
85 |
|
---|
86 | //resources are in Unicode format by default
|
---|
87 | isUnicode = TRUE;
|
---|
88 | }
|
---|
89 | //******************************************************************************
|
---|
90 | //******************************************************************************
|
---|
91 | Win32Resource::~Win32Resource()
|
---|
92 | {
|
---|
93 | Win32Resource *res = module->winres;
|
---|
94 |
|
---|
95 | if(os2resdata && (resType == RSRC_PELOADER || resType == RSRC_CUSTOMINDIRECT))
|
---|
96 | free(os2resdata);
|
---|
97 |
|
---|
98 | if(winresdata) free(winresdata);
|
---|
99 |
|
---|
100 | resmutex.enter();
|
---|
101 | if(res == this) {
|
---|
102 | module->winres = res->next;
|
---|
103 | }
|
---|
104 | else {
|
---|
105 | while(res->next != this) {
|
---|
106 | res = res->next;
|
---|
107 | }
|
---|
108 | if(res)
|
---|
109 | res->next = next;
|
---|
110 | }
|
---|
111 | resmutex.leave();
|
---|
112 | }
|
---|
113 | //******************************************************************************
|
---|
114 | //******************************************************************************
|
---|
115 | PVOID Win32Resource::lockResource()
|
---|
116 | {
|
---|
117 | dprintf(("Win32Resource::lockResource %d %x\n", id, winresdata));
|
---|
118 |
|
---|
119 | if(winresdata)
|
---|
120 | return(winresdata);
|
---|
121 |
|
---|
122 | dprintf(("Win32Resource::lockResource: NO windows resource!"));
|
---|
123 | return NULL;
|
---|
124 | }
|
---|
125 | //******************************************************************************
|
---|
126 | //******************************************************************************
|
---|
127 | PVOID Win32Resource::lockOS2Resource()
|
---|
128 | {
|
---|
129 | APIRET rc;
|
---|
130 | PVOID resdata;
|
---|
131 |
|
---|
132 | dprintf(("Win32Resource::lockOS2Resource %d\n", id));
|
---|
133 | if(os2resdata == NULL) {
|
---|
134 | os2resdata = convertResource(winresdata);
|
---|
135 | }
|
---|
136 | return os2resdata;
|
---|
137 | }
|
---|
138 | //******************************************************************************
|
---|
139 | //return size of converted win32 resource
|
---|
140 | //******************************************************************************
|
---|
141 | ULONG Win32Resource::getOS2Size()
|
---|
142 | {
|
---|
143 | switch(type) {
|
---|
144 | case NTRT_NEWBITMAP:
|
---|
145 | case NTRT_BITMAP:
|
---|
146 | return QueryConvertedBitmapSize((WINBITMAPINFOHEADER *)winresdata, ressize);
|
---|
147 |
|
---|
148 | case NTRT_CURSOR:
|
---|
149 | return QueryConvertedCursorSize((CursorComponent *)winresdata, ressize);
|
---|
150 |
|
---|
151 | case NTRT_ICON:
|
---|
152 | return QueryConvertedIconSize((WINBITMAPINFOHEADER *)winresdata, ressize);
|
---|
153 |
|
---|
154 | case NTRT_GROUP_ICON:
|
---|
155 | case NTRT_GROUP_CURSOR:
|
---|
156 | case NTRT_ACCELERATORS:
|
---|
157 | case NTRT_NEWMENU:
|
---|
158 | case NTRT_MENU:
|
---|
159 | case NTRT_NEWDIALOG:
|
---|
160 | case NTRT_DIALOG:
|
---|
161 | case NTRT_FONTDIR:
|
---|
162 | case NTRT_FONT:
|
---|
163 | case NTRT_MESSAGETABLE:
|
---|
164 | case NTRT_RCDATA:
|
---|
165 | case NTRT_VERSION:
|
---|
166 | case NTRT_STRING:
|
---|
167 | default:
|
---|
168 | dprintf(("Win32Resource::getOS2Size SHOULDN'T BE CALLED for this resource type (%d) (NOT IMPLEMENTED)!!", type));
|
---|
169 | break;
|
---|
170 | }
|
---|
171 | return 0;
|
---|
172 | }
|
---|
173 | //******************************************************************************
|
---|
174 | //******************************************************************************
|
---|
175 | PVOID Win32Resource::convertResource(void *win32res)
|
---|
176 | {
|
---|
177 | int cvtressize;
|
---|
178 |
|
---|
179 | switch(type) {
|
---|
180 | case NTRT_NEWBITMAP:
|
---|
181 | case NTRT_BITMAP:
|
---|
182 | return ConvertBitmap((WINBITMAPINFOHEADER *)win32res, ressize, &ressize);
|
---|
183 |
|
---|
184 | case NTRT_CURSOR:
|
---|
185 | return ConvertCursor((CursorComponent *)win32res, ressize, &cvtressize);
|
---|
186 |
|
---|
187 | case NTRT_GROUP_CURSOR:
|
---|
188 | return ConvertCursorGroup((CursorHeader *)win32res, ressize, module);
|
---|
189 |
|
---|
190 | case NTRT_GROUP_ICON:
|
---|
191 | return ConvertIconGroup((IconHeader *)win32res, ressize, module);
|
---|
192 |
|
---|
193 | case NTRT_ICON:
|
---|
194 | return ConvertIcon((WINBITMAPINFOHEADER *)win32res, ressize, &cvtressize);
|
---|
195 |
|
---|
196 | case NTRT_ACCELERATORS:
|
---|
197 | return ConvertAccelerator((WINACCEL *)win32res, ressize);
|
---|
198 |
|
---|
199 | case NTRT_NEWMENU:
|
---|
200 | case NTRT_MENU:
|
---|
201 | case NTRT_NEWDIALOG:
|
---|
202 | case NTRT_DIALOG:
|
---|
203 | case NTRT_FONTDIR:
|
---|
204 | case NTRT_FONT:
|
---|
205 | case NTRT_MESSAGETABLE:
|
---|
206 | case NTRT_RCDATA:
|
---|
207 | case NTRT_VERSION:
|
---|
208 | case NTRT_STRING:
|
---|
209 | break;
|
---|
210 |
|
---|
211 | default:
|
---|
212 | break;
|
---|
213 | }
|
---|
214 | dprintf(("Win32Resource::convertResource: Can't convert resource %d (type %d)", id, type));
|
---|
215 | return 0;
|
---|
216 | }
|
---|
217 | //******************************************************************************
|
---|
218 | //******************************************************************************
|
---|
219 | void Win32Resource::destroyAll(Win32ImageBase *module)
|
---|
220 | {
|
---|
221 | Win32Resource *res = module->winres, *next;
|
---|
222 |
|
---|
223 | while(res) {
|
---|
224 | next = res->next;
|
---|
225 | delete(res);
|
---|
226 | res = next;
|
---|
227 | }
|
---|
228 | }
|
---|
229 | //******************************************************************************
|
---|
230 | //******************************************************************************
|
---|