source: trunk/src/pe2lx/menu.cpp@ 97

Last change on this file since 97 was 97, checked in by phaller, 26 years ago

Add: added cvs variable $Id$ to source files.

File size: 8.6 KB
Line 
1/* $Id: menu.cpp,v 1.3 1999-06-10 17:08:54 phaller Exp $ */
2
3/*
4 * PE2LX menu conversion 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#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 <pmmenu.h>
19#include <stdio.h>
20#include <string.h>
21#include <stdlib.h>
22#include <iostream.h>
23#include <string.h>
24#include "pefile.h"
25#include "lx.h"
26#include "menu.h"
27#include "misc.h"
28
29static int ProcessSubMenu(PopupMenuItem *popupitem, MT_OS2 *os2menu, MTI_OS2 *menuitem, int size);
30static int ProcessMenuItem(NormalMenuItem *popupitem, MT_OS2 *os2menu, MTI_OS2 *menuitem, int size);
31static void menustrcpy(char *dest, char *src);
32//******************************************************************************
33//******************************************************************************
34void ShowMenu(int id, MenuHeader *menu, int size)
35{
36 PopupMenuItem *popupitem = (PopupMenuItem *)((char *)menu + sizeof(MenuHeader));
37 NormalMenuItem *normalitem = (NormalMenuItem *)((char *)menu + sizeof(MenuHeader));
38 MT_OS2 *os2menu, *submenu;
39 MTI_OS2 *menuitem;
40 int newsize;
41
42 //First save original win32 resource
43 OS2Exe.StoreWin32Resource(id, RT_MENU, size, (char *)menu);
44
45 os2menu = (MT_OS2 *)malloc(size*4); //should always be sufficient
46 os2menu->len = sizeof(MT_OS2) - sizeof(MTI_OS2);
47 os2menu->codepage = 437;
48 os2menu->reserved = 4;
49 os2menu->cMti = 0;
50 menuitem = &os2menu->rgMti[0];
51 submenu = os2menu;
52 while(size > 4) {
53 if(popupitem->fItemFlags & POPUP) {
54 cout << "POPUP ";
55 newsize = ProcessSubMenu(popupitem, os2menu, menuitem, size);
56 }
57 else newsize = ProcessMenuItem(normalitem, os2menu, menuitem, size);
58
59 if(popupitem->fItemFlags & ENDMENU) break;
60
61 popupitem = (PopupMenuItem *)((char *)popupitem + (size - newsize));
62 normalitem = (NormalMenuItem *)((char *)normalitem + (size - newsize));
63
64 menuitem = (MTI_OS2 *)((int)os2menu + os2menu->len);
65 size = newsize;
66 }
67 OS2Exe.StoreResource(id, RT_MENU, os2menu->len, (char *)os2menu);
68 free(os2menu);
69}
70//******************************************************************************
71//******************************************************************************
72static int ProcessSubMenu(PopupMenuItem *popupitem, MT_OS2 *os2menu, MTI_OS2 *menuitem, int size)
73{
74NormalMenuItem *normalitem;
75MT_OS2 *submenu;
76int len = 0, newsize;
77
78 menuitem->afStyle = MIS_SUBMENU;
79
80 //A unique id is sufficient, since it's not possible to get info about
81 //the SUBMENU item being selected with the (win32) WM_INITMENU message
82 //(this is possible in OS/2)
83 menuitem->idItem = (USHORT)OS2Exe.GetUniqueId();
84 menuitem->pad = 0;
85
86 if(popupitem->fItemFlags & GRAYED) {
87 cout << "GRAYED ";
88 menuitem->pad |= MIA_DISABLED;
89 }
90 if(popupitem->fItemFlags & INACTIVE) {
91 cout << "INACTIVE ";
92 menuitem->pad |= MIA_DISABLED;
93 }
94 if(popupitem->fItemFlags & BITMAP) {
95 cout << "BITMAP ";
96 //where's the bitmap stored? (same id as id of this menu item?)
97 menuitem->afStyle |= MIS_BITMAP;
98 }
99 if(popupitem->fItemFlags & OWNERDRAW) {
100 cout << "OWNERDRAW ";
101 menuitem->afStyle |= MIS_OWNERDRAW;
102 }
103 if(popupitem->fItemFlags & CHECKED) {
104 menuitem->pad |= MIA_CHECKED;
105 cout << "CHECKED ";
106 }
107 if(popupitem->fItemFlags & MENUBREAK) {
108 menuitem->afStyle |= MIS_BREAK;
109 menuitem->pad |= MIA_DISABLED;
110 cout << "MENUBREAK ";
111 }
112 if(popupitem->fItemFlags & MENUBARBREAK) {
113 cout << "MENUBARBREAK" << endl;
114 menuitem->afStyle |= MIS_BREAKSEPARATOR;
115 menuitem->pad |= MIA_DISABLED;
116 menuitem->c[0] = 0;
117 menuitem->c[1] = 0;
118 }
119 else {
120 len = (UniStrlen(popupitem->szItemText)+1)*2;
121 cout << UnicodeToAscii(popupitem->szItemText) << endl;
122 menustrcpy(menuitem->c, UnicodeToAscii(popupitem->szItemText));
123 }
124 os2menu->len += sizeof(MTI_OS2);
125 if(len > 4) os2menu->len += (len/2 - sizeof(menuitem->c));
126 os2menu->cMti++;
127
128 size -= (sizeof(PopupMenuItem)-2 + len); /*PLF Sat 97-06-21 22:17:51*/
129 //process next menu item
130 submenu = (MT_OS2 *)(menuitem+1);
131 if(len > 4)
132 submenu = (MT_OS2 *)((char *)submenu + len/2 - sizeof(menuitem->c));
133 submenu->len = sizeof(MT_OS2) - sizeof(MTI_OS2);
134 submenu->codepage = 437;
135 submenu->reserved = 4;
136 submenu->cMti = 0;
137 menuitem = &submenu->rgMti[0];
138
139 //normalitem = (NormalMenuItem *)(popupitem + 1);
140 normalitem = (NormalMenuItem *)((char*)popupitem + sizeof(PopupMenuItem)-2); /*PLF Sat 97-06-21 23:54:50*/
141 normalitem = (NormalMenuItem *)((int)normalitem + len);
142
143 while(size > 4) {
144 if(normalitem->fItemFlags & POPUP) {
145 cout << "POPUP ";
146 newsize = ProcessSubMenu((PopupMenuItem *)normalitem, submenu, menuitem, size);
147 }
148 else newsize = ProcessMenuItem(normalitem, submenu, menuitem, size);
149
150 menuitem = (MTI_OS2 *)((int)submenu + submenu->len);
151 if(normalitem->fItemFlags & ENDMENU) {
152 os2menu->len += submenu->len;
153 return(newsize);
154 }
155 normalitem = (NormalMenuItem *)((char *)normalitem + (size - newsize));
156 size = newsize;
157 }
158 os2menu->len += submenu->len;
159 return(size);
160}
161//******************************************************************************
162//******************************************************************************
163static int ProcessMenuItem(NormalMenuItem *normalitem, MT_OS2 *os2menu, MTI_OS2 *menuitem, int size)
164{
165WCHAR *menustring;
166int len = 0;
167
168 cout << "ID " << normalitem->wMenuID << " ";
169 menustring = normalitem->szItemText;
170 menuitem->afStyle = MIS_TEXT;
171 menuitem->idItem = normalitem->wMenuID;
172 menuitem->pad = 0;
173
174 if(normalitem->fItemFlags & ENDMENU) {
175 //signals the end of a (sub)menu
176 cout << "ENDMENU ";
177 len = (UniStrlen(normalitem->szItemText)+1)*2;
178 //don't store this menu item, is it's empty
179 if(len == 2) {
180 size -= (sizeof(NormalMenuItem)-2 + len);
181 return(size);
182 }
183 }
184 if(normalitem->fItemFlags & GRAYED) {
185 cout << "GRAYED ";
186 menuitem->pad |= MIA_DISABLED;
187 }
188 if(normalitem->fItemFlags & INACTIVE) {
189 cout << "INACTIVE ";
190 menuitem->pad |= MIA_DISABLED;
191 }
192 if(normalitem->fItemFlags & BITMAP) {
193 cout << "BITMAP ";
194 //where's the bitmap stored? (same id as id of this menu item?)
195 menuitem->afStyle |= MIS_BITMAP;
196 }
197 if(normalitem->fItemFlags & OWNERDRAW) {
198 cout << "OWNERDRAW ";
199 menuitem->afStyle |= MIS_OWNERDRAW;
200 }
201 if(normalitem->fItemFlags & CHECKED) {
202 menuitem->pad |= MIA_CHECKED;
203 cout << "CHECKED ";
204 }
205 if(normalitem->fItemFlags & MENUBREAK) {
206 menuitem->afStyle |= MIS_BREAK;
207 menuitem->pad |= MIA_DISABLED;
208 cout << "MENUBREAK ";
209 }
210 if(normalitem->fItemFlags & MENUBARBREAK) {
211 cout << "MENUBARBREAK" << endl;
212 menuitem->afStyle |= MIS_BREAKSEPARATOR;
213 menuitem->pad |= MIA_DISABLED;
214 menuitem->c[0] = 0;
215 menuitem->c[1] = 0;
216 }
217 else {
218 len = (UniStrlen(normalitem->szItemText)+1)*2;
219 if(normalitem->fItemFlags == 0 && len == 2) {
220 cout << "SEPARATOR" << endl;
221 menuitem->afStyle = MIS_SEPARATOR;
222 menuitem->pad = MIA_DISABLED;
223 menuitem->idItem = 0xFFFF;
224 menuitem->c[0] = 0;
225 menuitem->c[1] = 0;
226 }
227 else {
228 cout << UnicodeToAscii(normalitem->szItemText) << endl;
229 menustrcpy(menuitem->c, UnicodeToAscii(normalitem->szItemText));
230 }
231 }
232 os2menu->len += sizeof(MTI_OS2);
233 //SvL: Bugfix (>4), 19-10-'97
234 if(len >= 4) os2menu->len += (len/2 - sizeof(menuitem->c));
235 else os2menu->len -= 2; //REQUIRED (even though mi->c[2])
236
237 os2menu->cMti++;
238
239 size -= (sizeof(NormalMenuItem)-2 + len); /*PLF Sat 97-06-21 22:19:57*/
240
241
242 return(size);
243}
244//******************************************************************************
245//******************************************************************************
246static void menustrcpy(char *dest, char *src)
247{
248 int i, len = strlen(src);
249
250 for(i=0;i<len;i++) {
251 if(src[i] == '&') dest[i] = '~';
252 else dest[i] = src[i];
253 }
254 dest[len] = 0;
255}
256//******************************************************************************
257//******************************************************************************
Note: See TracBrowser for help on using the repository browser.