| 1 | /* $Id: icongrp.cpp,v 1.1 1999-09-06 02:20:05 bird Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * PE2LX Icon group code
|
|---|
| 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 | /*******************************************************************************
|
|---|
| 14 | * Header Files *
|
|---|
| 15 | *******************************************************************************/
|
|---|
| 16 | #include <pe2lx.h>
|
|---|
| 17 | #include "icon.h"
|
|---|
| 18 | #include "icongrp.h"
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 | BOOL ShowGroupIcon(LXHeaderSuper &OS2Exe, int id, IconHeader *ihdr, int size)
|
|---|
| 22 | {
|
|---|
| 23 | BOOL rc = FALSE;
|
|---|
| 24 | void *pConverted;
|
|---|
| 25 | ULONG ulSize;
|
|---|
| 26 |
|
|---|
| 27 | ltasserthp(ihdr);
|
|---|
| 28 |
|
|---|
| 29 | pConverted = ConvertGroupIcon(OS2Exe, id, ihdr, size, (PULONG)SSToDS(&ulSize));
|
|---|
| 30 | if (pConverted != NULL)
|
|---|
| 31 | {
|
|---|
| 32 | rc = OS2Exe.StoreResource(id, RT_POINTER, ulSize, (char*)pConverted);
|
|---|
| 33 | free(pConverted);
|
|---|
| 34 | }
|
|---|
| 35 | else
|
|---|
| 36 | cout << "ShowGroupIcon: convert failed" << endl;
|
|---|
| 37 |
|
|---|
| 38 | return rc;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | void *ConvertGroupIcon(LXHeaderSuper &OS2Exe, int id, IconHeader *ihdr, int size, PULONG pulSize)
|
|---|
| 44 | {
|
|---|
| 45 | ResourceDirectory *rdir = (ResourceDirectory *)(ihdr + 1);
|
|---|
| 46 | int i, groupsize = 0;
|
|---|
| 47 | BITMAPARRAYFILEHEADER *bafh, *orgbafh;
|
|---|
| 48 | OS2Icon *icon;
|
|---|
| 49 | int rc;
|
|---|
| 50 |
|
|---|
| 51 | ltassert(ihdr);
|
|---|
| 52 | cout << "Icon Group id :" << id << endl;
|
|---|
| 53 | cout << "Icon Group type :" << ihdr->wType << endl;
|
|---|
| 54 | cout << "Icon Group count:" << ihdr->wCount << endl;
|
|---|
| 55 | for (i=0;i<ihdr->wCount;i++)
|
|---|
| 56 | {
|
|---|
| 57 | cout << "Icon :" << rdir->wNameOrdinal << endl;
|
|---|
| 58 | cout << "Width :" << (int)rdir->bWidth << endl;
|
|---|
| 59 | cout << "Height :" << (int)rdir->bHeight << endl;
|
|---|
| 60 | cout << "Colors :" << (int)rdir->bColorCount << endl;
|
|---|
| 61 | cout << "Bits :" << rdir->wBitCount << endl;
|
|---|
| 62 | cout << "ResBytes:" << rdir->lBytesInRes << endl;
|
|---|
| 63 | icon = OS2Icon::GetIcon(rdir->wNameOrdinal);
|
|---|
| 64 | if (icon)
|
|---|
| 65 | groupsize += icon->QueryIconSize();
|
|---|
| 66 | rdir++;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | ////@KSO: since the iconsize includes all bytes from bafh->bfh let us not count it twice
|
|---|
| 70 | //bafh = (BITMAPARRAYFILEHEADER *)malloc(groupsize+ihdr->wCount*(sizeof(BITMAPARRAYFILEHEADER)-sizeof(BITMAPFILEHEADER)));
|
|---|
| 71 |
|
|---|
| 72 | bafh = (BITMAPARRAYFILEHEADER *)malloc(groupsize+ihdr->wCount*sizeof(BITMAPARRAYFILEHEADER));
|
|---|
| 73 | memset((void*)bafh, 0xaa, groupsize+ihdr->wCount*sizeof(BITMAPARRAYFILEHEADER)); //@KSO: this makes comparing converteded files easier
|
|---|
| 74 |
|
|---|
| 75 | ltassert(bafh != NULL);
|
|---|
| 76 |
|
|---|
| 77 | orgbafh = bafh;
|
|---|
| 78 |
|
|---|
| 79 | rdir = (ResourceDirectory *)(ihdr + 1);
|
|---|
| 80 | for (i=0;i<ihdr->wCount;i++)
|
|---|
| 81 | {
|
|---|
| 82 | bafh->usType = BFT_BITMAPARRAY;
|
|---|
| 83 | bafh->cbSize = sizeof(BITMAPARRAYFILEHEADER);
|
|---|
| 84 | bafh->cxDisplay = 0;
|
|---|
| 85 | bafh->cyDisplay = 0;
|
|---|
| 86 | icon = OS2Icon::GetIcon(rdir->wNameOrdinal);
|
|---|
| 87 | if (icon == NULL)
|
|---|
| 88 | {
|
|---|
| 89 | cout << "Can't find icon!" << endl;
|
|---|
| 90 | rdir++;
|
|---|
| 91 | continue;
|
|---|
| 92 | }
|
|---|
| 93 | if (i < ihdr->wCount - 1)
|
|---|
| 94 | bafh->offNext = (int)&bafh->bfh - (int)orgbafh + icon->QueryIconSize();
|
|---|
| 95 | else
|
|---|
| 96 | bafh->offNext = 0;
|
|---|
| 97 |
|
|---|
| 98 | icon->SetIconHdrOffset((int)bafh - (int)orgbafh + sizeof(BITMAPARRAYFILEHEADER)-sizeof(BITMAPFILEHEADER));
|
|---|
| 99 |
|
|---|
| 100 | memcpy((char *)&bafh->bfh, (char *)icon->GetIconHeader(), icon->QueryIconSize());
|
|---|
| 101 | bafh = (BITMAPARRAYFILEHEADER *)((int)&bafh->bfh + icon->QueryIconSize());
|
|---|
| 102 | rdir++;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | ////@KSO: since the iconsize includes all bytes from bafh->bfh let us not count it twice
|
|---|
| 106 | //*pulSize = groupsize+ihdr->wCount*(sizeof(BITMAPARRAYFILEHEADER)-sizeof(BITMAPFILEHEADER));
|
|---|
| 107 |
|
|---|
| 108 | *pulSize = groupsize+ihdr->wCount*(sizeof(BITMAPARRAYFILEHEADER));
|
|---|
| 109 | return (void*)orgbafh;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 | ULONG QuerySizeGroupIcon(IconHeader *ihdr, int size)
|
|---|
| 115 | {
|
|---|
| 116 | ResourceDirectory *rdir = (ResourceDirectory *)(ihdr + 1);
|
|---|
| 117 | int i, groupsize = 0;
|
|---|
| 118 | OS2Icon *icon;
|
|---|
| 119 | int rc;
|
|---|
| 120 |
|
|---|
| 121 | ltassert(ihdr);
|
|---|
| 122 | for ( i = 0; i < ihdr->wCount; i++)
|
|---|
| 123 | {
|
|---|
| 124 | icon = OS2Icon::GetIcon(rdir->wNameOrdinal);
|
|---|
| 125 | if (icon)
|
|---|
| 126 | groupsize += icon->QueryIconSize();
|
|---|
| 127 | rdir++;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | return groupsize+ihdr->wCount*(sizeof(BITMAPARRAYFILEHEADER));
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|