source: trunk/src/kernel32/winres.cpp@ 2802

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

Added new logging feature

File size: 6.6 KB
Line 
1/* $Id: winres.cpp,v 1.26 2000-02-16 14:22:12 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#define DBG_LOCALLOG DBG_winres
36#include "dbglocal.h"
37
38VMutex resmutex;
39
40char *ResTypes[MAX_RES] =
41 {"niks", "CURSOR", "BITMAP", "ICON", "MENU", "DIALOG", "STRING",
42 "FONTDIR", "FONT", "ACCELERATOR", "RCDATA", "MESSAGETABLE",
43 "GROUP_CURSOR", "niks", "GROUP_ICON", "niks", "VERSION"};
44
45//******************************************************************************
46//******************************************************************************
47Win32Resource::Win32Resource() :
48 os2resdata(NULL), winresdata(NULL), resType(RSRC_CUSTOMNODATA)
49{
50 next = NULL;
51 module = NULL;
52
53 id = -1;
54 type = -1;
55 hres = 0;
56 OS2ResHandle = 0;
57 //resources are in Unicode format by default; indirectly created resources
58 //can also be in ascii format
59 isUnicode = TRUE;
60}
61//******************************************************************************
62//******************************************************************************
63Win32Resource::Win32Resource(Win32ImageBase *module, ULONG id, ULONG type,
64 ULONG size, char *resdata) : hres(NULL),
65 os2resdata(NULL), winresdata(NULL), resType(RSRC_PELOADER)
66{
67 resmutex.enter();
68 next = module->winres;
69 module->winres = this;
70 resmutex.leave();
71
72 this->module = module;
73 this->id = id;
74 this->type = type;
75 this->ressize = size;
76 winresdata = (char *)malloc(size+sizeof(WCHAR));
77 if(winresdata == NULL) {
78 DebugInt3();
79 return;
80 }
81 OS2ResHandle = 0;
82
83 if(type == NTRT_STRING) {
84 memcpy(winresdata, resdata, size);
85 ((USHORT *)winresdata)[size/sizeof(WCHAR)] = 0;
86// ((USHORT *)winresdata)[size/sizeof(WCHAR)-1] = 0;
87 }
88 else memcpy(winresdata, resdata, size);
89
90 //resources are in Unicode format by default
91 isUnicode = TRUE;
92}
93//******************************************************************************
94//******************************************************************************
95Win32Resource::~Win32Resource()
96{
97 Win32Resource *res = module->winres;
98
99 if(os2resdata && (resType == RSRC_PELOADER || resType == RSRC_CUSTOMINDIRECT))
100 free(os2resdata);
101
102 if(winresdata) free(winresdata);
103
104 resmutex.enter();
105 if(res == this) {
106 module->winres = res->next;
107 }
108 else {
109 while(res->next != this) {
110 res = res->next;
111 }
112 if(res)
113 res->next = next;
114 }
115 resmutex.leave();
116}
117//******************************************************************************
118//******************************************************************************
119PVOID Win32Resource::lockResource()
120{
121 dprintf(("Win32Resource::lockResource %d %x\n", id, winresdata));
122
123 if(winresdata)
124 return(winresdata);
125
126 dprintf(("Win32Resource::lockResource: NO windows resource!"));
127 return NULL;
128}
129//******************************************************************************
130//******************************************************************************
131PVOID Win32Resource::lockOS2Resource()
132{
133 APIRET rc;
134 PVOID resdata;
135
136 dprintf(("Win32Resource::lockOS2Resource %d\n", id));
137 if(os2resdata == NULL) {
138 os2resdata = convertResource(winresdata);
139 }
140 return os2resdata;
141}
142//******************************************************************************
143//return size of converted win32 resource
144//******************************************************************************
145ULONG Win32Resource::getOS2Size()
146{
147 switch(type) {
148 case NTRT_NEWBITMAP:
149 case NTRT_BITMAP:
150 return QueryConvertedBitmapSize((WINBITMAPINFOHEADER *)winresdata, ressize);
151
152 case NTRT_CURSOR:
153 return QueryConvertedCursorSize((CursorComponent *)winresdata, ressize);
154
155 case NTRT_ICON:
156 return QueryConvertedIconSize((WINBITMAPINFOHEADER *)winresdata, ressize);
157
158 case NTRT_GROUP_ICON:
159 case NTRT_GROUP_CURSOR:
160 case NTRT_ACCELERATORS:
161 case NTRT_NEWMENU:
162 case NTRT_MENU:
163 case NTRT_NEWDIALOG:
164 case NTRT_DIALOG:
165 case NTRT_FONTDIR:
166 case NTRT_FONT:
167 case NTRT_MESSAGETABLE:
168 case NTRT_RCDATA:
169 case NTRT_VERSION:
170 case NTRT_STRING:
171 default:
172 dprintf(("Win32Resource::getOS2Size SHOULDN'T BE CALLED for this resource type (%d) (NOT IMPLEMENTED)!!", type));
173 break;
174 }
175 return 0;
176}
177//******************************************************************************
178//******************************************************************************
179PVOID Win32Resource::convertResource(void *win32res)
180{
181 int cvtressize;
182
183 switch(type) {
184 case NTRT_NEWBITMAP:
185 case NTRT_BITMAP:
186 return ConvertBitmap((WINBITMAPINFOHEADER *)win32res, ressize, &ressize);
187
188 case NTRT_CURSOR:
189 return ConvertCursor((CursorComponent *)win32res, ressize, &cvtressize);
190
191 case NTRT_GROUP_CURSOR:
192 return ConvertCursorGroup((CursorHeader *)win32res, ressize, module);
193
194 case NTRT_GROUP_ICON:
195 return ConvertIconGroup((IconHeader *)win32res, ressize, module);
196
197 case NTRT_ICON:
198 return ConvertIcon((WINBITMAPINFOHEADER *)win32res, ressize, &cvtressize);
199
200 case NTRT_ACCELERATORS:
201 return ConvertAccelerator((WINACCEL *)win32res, ressize);
202
203 case NTRT_NEWMENU:
204 case NTRT_MENU:
205 case NTRT_NEWDIALOG:
206 case NTRT_DIALOG:
207 case NTRT_FONTDIR:
208 case NTRT_FONT:
209 case NTRT_MESSAGETABLE:
210 case NTRT_RCDATA:
211 case NTRT_VERSION:
212 case NTRT_STRING:
213 break;
214
215 default:
216 break;
217 }
218 dprintf(("Win32Resource::convertResource: Can't convert resource %d (type %d)", id, type));
219 return 0;
220}
221//******************************************************************************
222//******************************************************************************
223void Win32Resource::destroyAll(Win32ImageBase *module)
224{
225 Win32Resource *res = module->winres, *next;
226
227 while(res) {
228 next = res->next;
229 delete(res);
230 res = next;
231 }
232}
233//******************************************************************************
234//******************************************************************************
Note: See TracBrowser for help on using the repository browser.