| 1 | /* $Id: winres.cpp,v 1.25 1999-12-09 19:08:29 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));
|
|---|
| 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 | // ((USHORT *)winresdata)[size/sizeof(WCHAR)-1] = 0;
|
|---|
| 84 | }
|
|---|
| 85 | else memcpy(winresdata, resdata, size);
|
|---|
| 86 |
|
|---|
| 87 | //resources are in Unicode format by default
|
|---|
| 88 | isUnicode = TRUE;
|
|---|
| 89 | }
|
|---|
| 90 | //******************************************************************************
|
|---|
| 91 | //******************************************************************************
|
|---|
| 92 | Win32Resource::~Win32Resource()
|
|---|
| 93 | {
|
|---|
| 94 | Win32Resource *res = module->winres;
|
|---|
| 95 |
|
|---|
| 96 | if(os2resdata && (resType == RSRC_PELOADER || resType == RSRC_CUSTOMINDIRECT))
|
|---|
| 97 | free(os2resdata);
|
|---|
| 98 |
|
|---|
| 99 | if(winresdata) free(winresdata);
|
|---|
| 100 |
|
|---|
| 101 | resmutex.enter();
|
|---|
| 102 | if(res == this) {
|
|---|
| 103 | module->winres = res->next;
|
|---|
| 104 | }
|
|---|
| 105 | else {
|
|---|
| 106 | while(res->next != this) {
|
|---|
| 107 | res = res->next;
|
|---|
| 108 | }
|
|---|
| 109 | if(res)
|
|---|
| 110 | res->next = next;
|
|---|
| 111 | }
|
|---|
| 112 | resmutex.leave();
|
|---|
| 113 | }
|
|---|
| 114 | //******************************************************************************
|
|---|
| 115 | //******************************************************************************
|
|---|
| 116 | PVOID Win32Resource::lockResource()
|
|---|
| 117 | {
|
|---|
| 118 | dprintf(("Win32Resource::lockResource %d %x\n", id, winresdata));
|
|---|
| 119 |
|
|---|
| 120 | if(winresdata)
|
|---|
| 121 | return(winresdata);
|
|---|
| 122 |
|
|---|
| 123 | dprintf(("Win32Resource::lockResource: NO windows resource!"));
|
|---|
| 124 | return NULL;
|
|---|
| 125 | }
|
|---|
| 126 | //******************************************************************************
|
|---|
| 127 | //******************************************************************************
|
|---|
| 128 | PVOID Win32Resource::lockOS2Resource()
|
|---|
| 129 | {
|
|---|
| 130 | APIRET rc;
|
|---|
| 131 | PVOID resdata;
|
|---|
| 132 |
|
|---|
| 133 | dprintf(("Win32Resource::lockOS2Resource %d\n", id));
|
|---|
| 134 | if(os2resdata == NULL) {
|
|---|
| 135 | os2resdata = convertResource(winresdata);
|
|---|
| 136 | }
|
|---|
| 137 | return os2resdata;
|
|---|
| 138 | }
|
|---|
| 139 | //******************************************************************************
|
|---|
| 140 | //return size of converted win32 resource
|
|---|
| 141 | //******************************************************************************
|
|---|
| 142 | ULONG Win32Resource::getOS2Size()
|
|---|
| 143 | {
|
|---|
| 144 | switch(type) {
|
|---|
| 145 | case NTRT_NEWBITMAP:
|
|---|
| 146 | case NTRT_BITMAP:
|
|---|
| 147 | return QueryConvertedBitmapSize((WINBITMAPINFOHEADER *)winresdata, ressize);
|
|---|
| 148 |
|
|---|
| 149 | case NTRT_CURSOR:
|
|---|
| 150 | return QueryConvertedCursorSize((CursorComponent *)winresdata, ressize);
|
|---|
| 151 |
|
|---|
| 152 | case NTRT_ICON:
|
|---|
| 153 | return QueryConvertedIconSize((WINBITMAPINFOHEADER *)winresdata, ressize);
|
|---|
| 154 |
|
|---|
| 155 | case NTRT_GROUP_ICON:
|
|---|
| 156 | case NTRT_GROUP_CURSOR:
|
|---|
| 157 | case NTRT_ACCELERATORS:
|
|---|
| 158 | case NTRT_NEWMENU:
|
|---|
| 159 | case NTRT_MENU:
|
|---|
| 160 | case NTRT_NEWDIALOG:
|
|---|
| 161 | case NTRT_DIALOG:
|
|---|
| 162 | case NTRT_FONTDIR:
|
|---|
| 163 | case NTRT_FONT:
|
|---|
| 164 | case NTRT_MESSAGETABLE:
|
|---|
| 165 | case NTRT_RCDATA:
|
|---|
| 166 | case NTRT_VERSION:
|
|---|
| 167 | case NTRT_STRING:
|
|---|
| 168 | default:
|
|---|
| 169 | dprintf(("Win32Resource::getOS2Size SHOULDN'T BE CALLED for this resource type (%d) (NOT IMPLEMENTED)!!", type));
|
|---|
| 170 | break;
|
|---|
| 171 | }
|
|---|
| 172 | return 0;
|
|---|
| 173 | }
|
|---|
| 174 | //******************************************************************************
|
|---|
| 175 | //******************************************************************************
|
|---|
| 176 | PVOID Win32Resource::convertResource(void *win32res)
|
|---|
| 177 | {
|
|---|
| 178 | int cvtressize;
|
|---|
| 179 |
|
|---|
| 180 | switch(type) {
|
|---|
| 181 | case NTRT_NEWBITMAP:
|
|---|
| 182 | case NTRT_BITMAP:
|
|---|
| 183 | return ConvertBitmap((WINBITMAPINFOHEADER *)win32res, ressize, &ressize);
|
|---|
| 184 |
|
|---|
| 185 | case NTRT_CURSOR:
|
|---|
| 186 | return ConvertCursor((CursorComponent *)win32res, ressize, &cvtressize);
|
|---|
| 187 |
|
|---|
| 188 | case NTRT_GROUP_CURSOR:
|
|---|
| 189 | return ConvertCursorGroup((CursorHeader *)win32res, ressize, module);
|
|---|
| 190 |
|
|---|
| 191 | case NTRT_GROUP_ICON:
|
|---|
| 192 | return ConvertIconGroup((IconHeader *)win32res, ressize, module);
|
|---|
| 193 |
|
|---|
| 194 | case NTRT_ICON:
|
|---|
| 195 | return ConvertIcon((WINBITMAPINFOHEADER *)win32res, ressize, &cvtressize);
|
|---|
| 196 |
|
|---|
| 197 | case NTRT_ACCELERATORS:
|
|---|
| 198 | return ConvertAccelerator((WINACCEL *)win32res, ressize);
|
|---|
| 199 |
|
|---|
| 200 | case NTRT_NEWMENU:
|
|---|
| 201 | case NTRT_MENU:
|
|---|
| 202 | case NTRT_NEWDIALOG:
|
|---|
| 203 | case NTRT_DIALOG:
|
|---|
| 204 | case NTRT_FONTDIR:
|
|---|
| 205 | case NTRT_FONT:
|
|---|
| 206 | case NTRT_MESSAGETABLE:
|
|---|
| 207 | case NTRT_RCDATA:
|
|---|
| 208 | case NTRT_VERSION:
|
|---|
| 209 | case NTRT_STRING:
|
|---|
| 210 | break;
|
|---|
| 211 |
|
|---|
| 212 | default:
|
|---|
| 213 | break;
|
|---|
| 214 | }
|
|---|
| 215 | dprintf(("Win32Resource::convertResource: Can't convert resource %d (type %d)", id, type));
|
|---|
| 216 | return 0;
|
|---|
| 217 | }
|
|---|
| 218 | //******************************************************************************
|
|---|
| 219 | //******************************************************************************
|
|---|
| 220 | void Win32Resource::destroyAll(Win32ImageBase *module)
|
|---|
| 221 | {
|
|---|
| 222 | Win32Resource *res = module->winres, *next;
|
|---|
| 223 |
|
|---|
| 224 | while(res) {
|
|---|
| 225 | next = res->next;
|
|---|
| 226 | delete(res);
|
|---|
| 227 | res = next;
|
|---|
| 228 | }
|
|---|
| 229 | }
|
|---|
| 230 | //******************************************************************************
|
|---|
| 231 | //******************************************************************************
|
|---|