source: trunk/src/pe2lx/dialog.cpp@ 46

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

* empty log message *

File size: 34.9 KB
Line 
1/*
2 * PE2LX dialog conversion code
3 *
4 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
5 * Copyright 1998 Patrick Haller
6 * Copyright 1998 Peter Fitzsimmons
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#define INCL_WINMLE
18#include <os2.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 "dialog.h"
27#include "misc.h"
28
29#ifndef BS_TEXT /*PLF Sun 97-06-22 03:07:13 not in watcom's os/2 header */
30 #define BS_TEXT 0x0010
31#endif
32
33static int ConvertClassAndStyle(int winclass, int style, USHORT *os2class, BOOL *fIconBmp);
34static int ConvertDlgStyle(int style);
35static int ConvertDlgItemStyle(int style);
36static void ConvertCaption(ULONG style, char *caption);
37static int ConvertFont(char *font, PRESPARAMS *dlgpparam, int fsize);
38static void ShowDialogEx(int id, WINDLGTEMPLATEEX *dhdr, int size);
39
40//******************************************************************************
41//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
42//Used (slightly modified) in user32\dlgconvert.cpp too, so synch them when changed!!
43//ShowDialogEx is identical except for the different dialog(item) structures
44//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
45//******************************************************************************
46void ShowDialog(int id, DialogBoxHeader *dhdr, int size)
47{
48 WINDLGTEMPLATEEX *windlgex = (WINDLGTEMPLATEEX *)dhdr;
49 DLGTEMPLATE *dlgt;
50 DLGTITEM *dlgitem;
51 PRESPARAMS *dlgpparam;
52 char *dlgdata, *dlgcurdata;
53 WCHAR *szCaption;
54 WORD *ptrArray;
55 char *ctrltext, *szClass, *font;
56 FontHeader *fhdr;
57 ControlData *ctrldata;
58 int i;
59 ULONG ctrlflag, winclass;
60 BOOL fIconBmp;
61
62 //First save original win32 resource
63 OS2Exe.StoreWin32Resource(id, RT_DIALOG, size, (char *)dhdr);
64
65 if(windlgex->wDlgVer == 1 && windlgex->wSignature == 0xFFFF) {
66 ShowDialogEx(id, windlgex, size);
67 return;
68 }
69
70 //should be enough
71 dlgt = (DLGTEMPLATE *)malloc(sizeof(DLGTEMPLATE) + dhdr->NumberOfItems*sizeof(DLGTITEM) + size);
72 dlgitem = &dlgt->adlgti[0];
73 dlgdata = (char *)&dlgt->adlgti[dhdr->NumberOfItems+1]; //for control data, presparams & strings
74 memset((char *)dlgt, 0, sizeof(DLGTEMPLATE) + dhdr->NumberOfItems*sizeof(DLGTITEM) + size);
75 dlgcurdata = dlgdata;
76
77 dlgt->codepage = 437;
78 dlgt->offadlgti = 14;
79 dlgt->fsTemplateStatus = 1;
80 dlgt->iItemFocus = 65535;
81 dlgt->coffPresParams = 0;
82
83 dlgitem->flStyle = ConvertDlgStyle(dhdr->lStyle) | WS_SYNCPAINT | WS_CLIPSIBLINGS;
84
85 ctrlflag = 0;
86 if((dhdr->lStyle & WINWS_CAPTION) == WINWS_CAPTION) {
87 ctrlflag |= FCF_TITLEBAR;
88 dlgitem->flStyle |= FS_BORDER;
89 }
90 else
91 if(dhdr->lStyle & WINWS_DLGFRAME) //can't have title bar
92 dlgitem->flStyle |= FS_DLGBORDER;
93
94 if((dhdr->lStyle & (WINWS_SYSMENU | WINWS_CAPTION)) == (WINWS_SYSMENU | WINWS_CAPTION))
95 ctrlflag |= FCF_SYSMENU;
96 if(dhdr->lStyle & WINWS_VSCROLL)
97 ctrlflag |= FCF_VERTSCROLL;
98 if(dhdr->lStyle & WINWS_HSCROLL)
99 ctrlflag |= FCF_HORZSCROLL;
100 if(dhdr->lStyle & WINWS_MINIMIZEBOX)
101 ctrlflag |= FCF_MINBUTTON;
102 if(dhdr->lStyle & WINWS_MAXIMIZEBOX)
103 ctrlflag |= FCF_MAXBUTTON;
104 if(dhdr->lStyle & WINWS_THICKFRAME)
105 dlgitem->flStyle |= FS_SIZEBORDER;
106
107 if(ctrlflag) {
108 *(ULONG *)dlgcurdata = ctrlflag;
109 dlgitem->offCtlData = (USHORT)((int)dlgcurdata - (int)dlgt);
110 dlgcurdata += sizeof(ULONG);
111 }
112 else dlgitem->offCtlData = 0xFFFF;
113 dlgitem->x = dhdr->x;
114 //TODO: SvL: Calc has x = 32768 Special value???
115 if(dlgitem->x > 1024 || dlgitem->x < 0)
116 dlgitem->x = 64;
117
118 dlgitem->y = dhdr->y;
119 dlgitem->cx = dhdr->cx;
120 dlgitem->cy = dhdr->cy;
121 dlgitem->cChildren = dhdr->NumberOfItems;
122 dlgitem->id = (USHORT)id; //ord id or converted name id
123 dlgitem->fsItemStatus = 1;
124 dlgitem->offClassName = 1; //WC_FRAME
125
126 cout.setf(ios::hex, ios::basefield);
127 cout << "Dialog Style : " << dhdr->lStyle << endl;
128 cout << "Extended Dialog Style: " << dhdr->lExtendedStyle << endl;
129 cout.setf(ios::dec, ios::basefield);
130 cout << "Position : (" << dhdr->x << ',' << dhdr->y << ')' << endl;
131 cout << "Size : (" << dhdr->cx << ',' << dhdr->cy << ')' << endl;
132 cout << "Number of Items : " << dhdr->NumberOfItems << endl;
133 //Menu id
134 if(dhdr->fNameOrd == 0xFFFF) {
135 cout << "Menu ID : " << *(WORD *)(dhdr+1) << endl;
136 ptrArray = (WORD *)((int)dhdr + sizeof(DialogBoxHeader) + sizeof(WORD));
137 }
138 else {
139 if(dhdr->fNameOrd == 0) {//SvL: 0 == no menu!
140 ptrArray = (WORD *)((int)dhdr + sizeof(DialogBoxHeader));
141 }
142 else {
143 cout << "Menu namestring : " << UnicodeToAscii((WCHAR *)(&dhdr->fNameOrd)) << endl;
144 ptrArray = (WORD *)((int)&dhdr->fNameOrd + UniStrlen((WCHAR *)(&dhdr->fNameOrd))*2 + sizeof(WCHAR));
145 }
146 }
147 //Class id
148 if(*ptrArray == 0xFFFF) {
149 cout << "Class ID : " << *(WORD *)(ptrArray+1) << endl;
150 ptrArray = (WORD *)((int)ptrArray + 2*sizeof(WORD));
151 }
152 else {
153 if(*ptrArray == 0) {//SvL: 0 == no menu!
154 ptrArray = (WORD *)((int)ptrArray + sizeof(WORD));
155 }
156 else {
157 szClass = UnicodeToAscii((WCHAR *)ptrArray);
158 cout << "Class Name : " << szClass << endl;
159
160 dlgitem->cchClassName = (USHORT)strlen(szClass);
161 dlgitem->offClassName = (USHORT)((int)dlgcurdata - (int)dlgt);
162 strcpy((char *)dlgcurdata, szClass);
163 //Open32 wants class name in upper case!
164 UpCase((char *)dlgcurdata);
165 dlgcurdata += dlgitem->cchClassName + 1; //include terminating 0 (just to be sure)
166//TODO: SvL: Can they also be system classes?
167// dlgitem->flStyle = dhdr->lStyle;
168// dlgitem->flStyle = ConvertDlgItemStyle(dhdr->lStyle);
169 ptrArray = (WORD *)((int)ptrArray + UniStrlen((WCHAR *)(ptrArray))*2 + sizeof(WORD));
170 }
171 }
172
173 //Title
174 if(*ptrArray == 0) {
175 cout << "No title " << endl;
176 ctrldata = (ControlData *)((int)(int)ptrArray + sizeof(WORD));
177 }
178 else {
179 ctrltext = UnicodeToAscii((WCHAR *)(ptrArray));
180 cout << "Title : " << ctrltext << endl;
181 ctrldata = (ControlData *)((int)(int)ptrArray + UniStrlen((WCHAR *)(ptrArray))*2 + sizeof(WORD));
182
183 if(ctrltext[0] != 0) {
184 dlgitem->cchText = (USHORT)strlen(ctrltext);
185 dlgitem->offText = (USHORT)((int)dlgcurdata - (int)dlgt);
186 strcpy((char *)dlgcurdata, ctrltext);
187 dlgcurdata += dlgitem->cchText + 1; //include terminating 0 (just to be sure)
188 }
189 }
190
191 if(dhdr->lStyle & DS_SETFONT) {
192 fhdr = (FontHeader *)ctrldata;
193 font = UnicodeToAscii(fhdr->szFontName);
194 cout << "Font Point Size : " << fhdr->wPointSize << endl;
195 cout << "Font Name : " << font << endl;
196 ctrldata = (ControlData *)((int)fhdr + sizeof(FontHeader) - 2 + UniStrlen(fhdr->szFontName)*2 + sizeof(WORD)); /*PLF Sat 97-06-21 20:22:44*/
197 //TODO: no pres params yet (font in win32 dialog ignored)
198 dlgpparam = (PRESPARAMS *)dlgcurdata;
199 dlgpparam->cb = 0;
200 dlgpparam->aparam[0].id = PP_FONTNAMESIZE;
201 dlgpparam->aparam[0].cb = 0;
202 UpCase(font);
203 if(ConvertFont(font, dlgpparam, fhdr->wPointSize) == TRUE) {
204 dlgpparam->aparam[0].cb = strlen(dlgpparam->aparam[0].ab) + 2*sizeof(ULONG) + 1;
205// dlgpparam->cb = sizeof(ULONG) + dlgpparam->aparam[0].cb;
206 dlgpparam->cb = dlgpparam->aparam[0].cb;
207 dlgitem->offPresParams = (USHORT)((int)dlgpparam - (int)dlgt);
208 dlgcurdata += dlgpparam->cb + sizeof(ULONG);
209 }
210 }
211 dlgitem++;
212
213 ctrldata = (ControlData *)(((int)ctrldata+3) & ~3);
214 for(i=0;i<dhdr->NumberOfItems;i++) {
215 //save as OS/2 DLGTITEM
216 dlgitem->x = ctrldata->x;
217 //SvL: 3-8-'97
218 // OS/2 -> left bottom == origin and y coordinate == left bottom origin control
219 // Win32 -> left top == origin and y coordinate == left top origin
220 dlgitem->y = dlgt->adlgti[0].cy - ctrldata->y - ctrldata->cy;
221 dlgitem->cx = ctrldata->cx;
222 dlgitem->cy = ctrldata->cy;
223 dlgitem->id = ctrldata->wId;
224 dlgitem->offCtlData = 0xFFFF;
225 dlgitem->offPresParams = 0xFFFF;
226
227 //TODO: Extended style
228
229 cout.setf(ios::hex, ios::basefield);
230 cout << "***** Control Style : " << ctrldata->lStyle << endl;
231 cout << "Extended Control Style: " << ctrldata->lExtendedStyle << endl;
232 cout.setf(ios::dec, ios::basefield);
233 cout << "Position : (" << ctrldata->x << ',' << ctrldata->y << ')' << endl;
234 cout << "Size : (" << ctrldata->cx << ',' << ctrldata->cy << ')' << endl;
235 cout << "wID : " << ctrldata->wId << endl;
236 winclass = 0;
237 if(ctrldata->fClassId == 0xFFFF) {
238 winclass = *(WORD *)(ctrldata+1);
239 cout << "Class ID : " << winclass << endl;
240 szCaption = (WCHAR *)((int)ctrldata + sizeof(ControlData) + sizeof(WORD));
241 dlgitem->flStyle = ConvertClassAndStyle(*(WORD *)(ctrldata+1), ctrldata->lStyle, &dlgitem->offClassName, &fIconBmp);
242 dlgitem->cchClassName = 0;
243 }
244 else {
245 szClass = UnicodeToAscii((WCHAR *)&ctrldata->fClassId);
246 cout << "Class Name : " << szClass << endl;
247 szCaption = (WCHAR *)((int)ctrldata + sizeof(ControlData) + strlen(szClass)*2);
248 dlgitem->cchClassName = (USHORT)strlen(szClass);
249 dlgitem->offClassName = (USHORT)((int)dlgcurdata - (int)dlgt);
250 strcpy((char *)dlgcurdata, szClass);
251 //Open32 wants class name in upper case!
252 UpCase((char *)dlgcurdata);
253 dlgcurdata += dlgitem->cchClassName + 1; //include terminating 0 (just to be sure)
254 dlgitem->flStyle = ConvertDlgItemStyle(ctrldata->lStyle) ;
255 }
256 if(*(USHORT *)szCaption == 0xFFFF) {
257 szCaption += 2;
258 dlgitem->cchText = 0;
259 dlgitem->offText = 0;
260 }
261 else { //Handle Caption
262 ctrltext = UnicodeToAscii(szCaption);
263 //SvL: (16-9-'97) Convert '&' chars to '~' (for some classes)
264 ConvertCaption(winclass, ctrltext);
265 if(fIconBmp == TRUE) {//control contains bitmap or icon
266 dlgitem->offText = (USHORT)((int)dlgcurdata - (int)dlgt);
267 int resid = OS2Exe.ConvertNametoId(ctrltext);
268 *(char *)dlgcurdata = '#';
269 itoa(resid, (char *)dlgcurdata+1, 10);
270 dlgitem->cchText = (USHORT)strlen((char *)dlgcurdata); //one USHORT for res id
271 dlgcurdata += dlgitem->cchText + 1; //include terminating 0 (just to be sure)
272 }
273 else {
274 if(ctrltext[0] != 0) {
275 dlgitem->cchText = (USHORT)strlen(ctrltext);
276 dlgitem->offText = (USHORT)((int)dlgcurdata - (int)dlgt);
277 strcpy((char *)dlgcurdata, ctrltext);
278 dlgcurdata += dlgitem->cchText + 1; //include terminating 0 (just to be sure)
279 }
280 }
281 cout << "Text : " << UnicodeToAscii(szCaption) << endl;
282 szCaption = (WCHAR *)((int)szCaption + UniStrlen(szCaption)*2 + sizeof(WORD));
283 }
284
285 cout << "Extra Stuff WORD : " << *(WORD *)(szCaption) << endl;
286 ctrldata = (ControlData *)((int)szCaption + sizeof(WORD));
287 ctrldata = (ControlData *)(((int)ctrldata+3) & ~3);
288 dlgitem++;
289 }
290 //calculate dialog box length
291 dlgt->cbTemplate = (USHORT)((int)dlgcurdata - (int)dlgt);
292 OS2Exe.StoreResource(id, RT_DIALOG, dlgt->cbTemplate, (char *)dlgt);
293 free(dlgt);
294}
295//******************************************************************************
296//******************************************************************************
297void ShowDialogEx(int id, WINDLGTEMPLATEEX *dhdr, int size)
298{
299 DLGTEMPLATE *dlgt;
300 DLGTITEM *dlgitem;
301 PRESPARAMS *dlgpparam;
302 char *dlgdata, *dlgcurdata;
303 WCHAR *szCaption;
304 WORD *ptrArray;
305 char *ctrltext, *szClass, *font;
306 FontHeaderEx *fhdr;
307 WINDLGITEMTEMPLATEEX *ctrldata;
308 int i;
309 ULONG ctrlflag, winclass;
310 BOOL fIconBmp;
311
312 //should be enough
313 dlgt = (DLGTEMPLATE *)malloc(sizeof(DLGTEMPLATE) + dhdr->NumberOfItems*sizeof(DLGTITEM) + size);
314 dlgitem = &dlgt->adlgti[0];
315 dlgdata = (char *)&dlgt->adlgti[dhdr->NumberOfItems+1]; //for control data, presparams & strings
316 memset((char *)dlgt, 0, sizeof(DLGTEMPLATE) + dhdr->NumberOfItems*sizeof(DLGTITEM) + size);
317 dlgcurdata = dlgdata;
318
319 dlgt->codepage = 437;
320 dlgt->offadlgti = 14;
321 dlgt->fsTemplateStatus = 1;
322 dlgt->iItemFocus = 65535;
323 dlgt->coffPresParams = 0;
324
325 dlgitem->flStyle = ConvertDlgStyle(dhdr->lStyle) | WS_SYNCPAINT | WS_CLIPSIBLINGS;
326
327 ctrlflag = 0;
328 if((dhdr->lStyle & WINWS_CAPTION) == WINWS_CAPTION) {
329 ctrlflag |= FCF_TITLEBAR;
330 dlgitem->flStyle |= FS_BORDER;
331 }
332 else
333 if(dhdr->lStyle & WINWS_DLGFRAME) //can't have title bar
334 dlgitem->flStyle |= FS_DLGBORDER;
335
336 if((dhdr->lStyle & (WINWS_SYSMENU | WINWS_CAPTION)) == (WINWS_SYSMENU | WINWS_CAPTION))
337 ctrlflag |= FCF_SYSMENU;
338 if(dhdr->lStyle & WINWS_VSCROLL)
339 ctrlflag |= FCF_VERTSCROLL;
340 if(dhdr->lStyle & WINWS_HSCROLL)
341 ctrlflag |= FCF_HORZSCROLL;
342 if(dhdr->lStyle & WINWS_MINIMIZEBOX)
343 ctrlflag |= FCF_MINBUTTON;
344 if(dhdr->lStyle & WINWS_MAXIMIZEBOX)
345 ctrlflag |= FCF_MAXBUTTON;
346 if(dhdr->lStyle & WINWS_THICKFRAME)
347 dlgitem->flStyle |= FS_SIZEBORDER;
348
349 if(ctrlflag) {
350 *(ULONG *)dlgcurdata = ctrlflag;
351 dlgitem->offCtlData = (USHORT)((int)dlgcurdata - (int)dlgt);
352 dlgcurdata += sizeof(ULONG);
353 }
354 else dlgitem->offCtlData = 0xFFFF;
355 dlgitem->x = dhdr->x;
356 dlgitem->y = dhdr->y;
357 dlgitem->cx = dhdr->cx;
358 dlgitem->cy = dhdr->cy;
359 dlgitem->cChildren = dhdr->NumberOfItems;
360 dlgitem->id = (USHORT)id; //ord id or converted name id
361 dlgitem->fsItemStatus = 1;
362 dlgitem->offClassName = 1; //WC_FRAME
363
364 cout.setf(ios::hex, ios::basefield);
365 cout << "Dialog Style : " << dhdr->lStyle << endl;
366 cout << "Extended Dialog Style: " << dhdr->lExtendedStyle << endl;
367 cout.setf(ios::dec, ios::basefield);
368 cout << "Position : (" << dhdr->x << ',' << dhdr->y << ')' << endl;
369 cout << "Size : (" << dhdr->cx << ',' << dhdr->cy << ')' << endl;
370 cout << "Number of Items : " << dhdr->NumberOfItems << endl;
371 //Menu id
372 if(dhdr->fNameOrd == 0xFFFF) {
373 cout << "Menu ID : " << *(WORD *)(dhdr+1) << endl;
374 ptrArray = (WORD *)((int)dhdr + sizeof(WINDLGTEMPLATEEX) + sizeof(WORD));
375 }
376 else {
377 if(dhdr->fNameOrd == 0) {//SvL: 0 == no menu!
378 ptrArray = (WORD *)((int)dhdr + sizeof(WINDLGTEMPLATEEX));
379 }
380 else {
381 cout << "Menu namestring : " << UnicodeToAscii((WCHAR *)(&dhdr->fNameOrd)) << endl;
382 ptrArray = (WORD *)((int)&dhdr->fNameOrd + UniStrlen((WCHAR *)(&dhdr->fNameOrd))*2 + sizeof(WCHAR));
383 }
384 }
385 //Class id
386 if(*ptrArray == 0xFFFF) {
387 cout << "Class ID : " << *(WORD *)(ptrArray+1) << endl;
388 ptrArray = (WORD *)((int)ptrArray + 2*sizeof(WORD));
389 }
390 else {
391 if(*ptrArray == 0) {//SvL: 0 == no menu!
392 ptrArray = (WORD *)((int)ptrArray + sizeof(WORD));
393 }
394 else {
395 szClass = UnicodeToAscii((WCHAR *)ptrArray);
396 cout << "Class Name : " << szClass << endl;
397
398 dlgitem->cchClassName = (USHORT)strlen(szClass);
399 dlgitem->offClassName = (USHORT)((int)dlgcurdata - (int)dlgt);
400 strcpy((char *)dlgcurdata, szClass);
401 //Open32 wants class name in upper case!
402 UpCase((char *)dlgcurdata);
403 dlgcurdata += dlgitem->cchClassName + 1; //include terminating 0 (just to be sure)
404//TODO: SvL: Can they also be system classes?
405// dlgitem->flStyle = dhdr->lStyle;
406// dlgitem->flStyle = ConvertDlgItemStyle(dhdr->lStyle);
407 ptrArray = (WORD *)((int)ptrArray + UniStrlen((WCHAR *)(ptrArray))*2 + sizeof(WORD));
408 }
409 }
410
411 //Title
412 if(*ptrArray == 0) {
413 cout << "No title " << endl;
414 ctrldata = (WINDLGITEMTEMPLATEEX *)((int)(int)ptrArray + sizeof(WORD));
415 }
416 else {
417 ctrltext = UnicodeToAscii((WCHAR *)(ptrArray));
418 cout << "Title : " << ctrltext << endl;
419 ctrldata = (WINDLGITEMTEMPLATEEX *)((int)(int)ptrArray + UniStrlen((WCHAR *)(ptrArray))*2 + sizeof(WORD));
420
421 if(ctrltext[0] != 0) {
422 dlgitem->cchText = (USHORT)strlen(ctrltext);
423 dlgitem->offText = (USHORT)((int)dlgcurdata - (int)dlgt);
424 strcpy((char *)dlgcurdata, ctrltext);
425 dlgcurdata += dlgitem->cchText + 1; //include terminating 0 (just to be sure)
426 }
427 }
428 dlgitem++;
429
430 if(dhdr->lStyle & DS_SETFONT) {
431 fhdr = (FontHeaderEx *)ctrldata;
432 font = UnicodeToAscii(fhdr->szFontName);
433 cout << "Font Point Size : " << fhdr->wPointSize << endl;
434 cout << "Font Name : " << font << endl;
435 ctrldata = (WINDLGITEMTEMPLATEEX *)((int)fhdr + sizeof(FontHeaderEx) - 2 + UniStrlen(fhdr->szFontName)*2 + sizeof(WORD)); /*PLF Sat 97-06-21 20:22:44*/
436 //TODO: no pres params yet (font in win32 dialog ignored)
437 dlgpparam = (PRESPARAMS *)dlgcurdata;
438 dlgpparam->cb = 0;
439 dlgpparam->aparam[0].id = PP_FONTNAMESIZE;
440 dlgpparam->aparam[0].cb = 0;
441 UpCase(font);
442 if(ConvertFont(font, dlgpparam, fhdr->wPointSize) == TRUE) {
443 dlgpparam->aparam[0].cb = strlen(dlgpparam->aparam[0].ab) + 2*sizeof(ULONG) + 1;
444 dlgpparam->cb = sizeof(ULONG) + dlgpparam->aparam[0].cb;
445 dlgt->coffPresParams = (USHORT)((int)dlgpparam - (int)dlgt);
446 dlgcurdata += dlgpparam->cb;
447 }
448 }
449 ctrldata = (WINDLGITEMTEMPLATEEX *)(((int)ctrldata+3) & ~3);
450 for(i=0;i<dhdr->NumberOfItems;i++) {
451 //save as OS/2 DLGTITEM
452 dlgitem->x = ctrldata->x;
453 //SvL: 3-8-'97
454 // OS/2 -> left bottom == origin and y coordinate == left bottom origin control
455 // Win32 -> left top == origin and y coordinate == left top origin
456 dlgitem->y = dlgt->adlgti[0].cy - ctrldata->y - ctrldata->cy;
457 dlgitem->cx = ctrldata->cx;
458 dlgitem->cy = ctrldata->cy;
459 dlgitem->id = (USHORT)ctrldata->wId;
460 dlgitem->offCtlData = 0xFFFF;
461 dlgitem->offPresParams = 0xFFFF;
462
463 //TODO: Extended style
464
465 cout.setf(ios::hex, ios::basefield);
466 cout << "***** Control Style : " << ctrldata->lStyle << endl;
467 cout << "Extended Control Style: " << ctrldata->lExtendedStyle << endl;
468 cout.setf(ios::dec, ios::basefield);
469 cout << "Position : (" << ctrldata->x << ',' << ctrldata->y << ')' << endl;
470 cout << "Size : (" << ctrldata->cx << ',' << ctrldata->cy << ')' << endl;
471 cout << "wID : " << ctrldata->wId << endl;
472 winclass = 0;
473 if(ctrldata->fClassId == 0xFFFF) {
474 winclass = *(WORD *)(ctrldata+1);
475 cout << "Class ID : " << winclass << endl;
476 szCaption = (WCHAR *)((int)ctrldata + sizeof(WINDLGITEMTEMPLATEEX) + sizeof(WORD));
477 dlgitem->flStyle = ConvertClassAndStyle(*(WORD *)(ctrldata+1), ctrldata->lStyle, &dlgitem->offClassName, &fIconBmp);
478 dlgitem->cchClassName = 0;
479 }
480 else {
481 szClass = UnicodeToAscii((WCHAR *)&ctrldata->fClassId);
482 cout << "Class Name : " << szClass << endl;
483 szCaption = (WCHAR *)((int)ctrldata + sizeof(WINDLGITEMTEMPLATEEX) + strlen(szClass)*2);
484 dlgitem->cchClassName = (USHORT)strlen(szClass);
485 dlgitem->offClassName = (USHORT)((int)dlgcurdata - (int)dlgt);
486 strcpy((char *)dlgcurdata, szClass);
487 //Open32 wants class name in upper case!
488 UpCase((char *)dlgcurdata);
489 dlgcurdata += dlgitem->cchClassName + 1; //include terminating 0 (just to be sure)
490 dlgitem->flStyle = ConvertDlgItemStyle(ctrldata->lStyle) ;
491 }
492 if(*(USHORT *)szCaption == 0xFFFF) {
493 szCaption += 2;
494 }
495 else { //Handle Caption
496 ctrltext = UnicodeToAscii(szCaption);
497 //SvL: (16-9-'97) Convert '&' chars to '~' (for some classes)
498 ConvertCaption(winclass, ctrltext);
499 if(fIconBmp == TRUE) {//control contains bitmap or icon
500 dlgitem->offText = (USHORT)((int)dlgcurdata - (int)dlgt);
501 int resid = OS2Exe.ConvertNametoId(ctrltext);
502 *(char *)dlgcurdata = '#';
503 itoa(resid, (char *)dlgcurdata+1, 10);
504 dlgitem->cchText = (USHORT)strlen((char *)dlgcurdata); //one USHORT for res id
505 dlgcurdata += dlgitem->cchText + 1; //include terminating 0 (just to be sure)
506 }
507 else {
508 if(ctrltext[0] != 0) {
509 dlgitem->cchText = (USHORT)strlen(ctrltext);
510 dlgitem->offText = (USHORT)((int)dlgcurdata - (int)dlgt);
511 strcpy((char *)dlgcurdata, ctrltext);
512 dlgcurdata += dlgitem->cchText + 1; //include terminating 0 (just to be sure)
513 }
514 }
515 cout << "Text : " << UnicodeToAscii(szCaption) << endl;
516 szCaption = (WCHAR *)((int)szCaption + UniStrlen(szCaption)*2 + sizeof(WORD));
517 }
518
519 cout << "Extra Stuff WORD : " << *(WORD *)(szCaption) << endl;
520 ctrldata = (WINDLGITEMTEMPLATEEX *)((int)szCaption + sizeof(WORD));
521 ctrldata = (WINDLGITEMTEMPLATEEX *)(((int)ctrldata+3) & ~3);
522 dlgitem++;
523 }
524 //calculate dialog box length
525 dlgt->cbTemplate = (USHORT)((int)dlgcurdata - (int)dlgt);
526 OS2Exe.StoreResource(id, RT_DIALOG, dlgt->cbTemplate, (char *)dlgt);
527 free(dlgt);
528}
529//******************************************************************************
530//******************************************************************************
531static int ConvertClassAndStyle(int winclass,
532 int style,
533 USHORT *os2class,
534 BOOL *fIconBmp)
535{
536 int os2style = ConvertDlgItemStyle(style);
537
538 *fIconBmp = FALSE;
539 style &= 0xFFFF;
540
541 switch(winclass) {
542 case WIN_BUTTON:
543#if 0
544 if(style & WINBS_LEFTTEXT)
545 os2style |= ;
546#endif
547 style &= 0xF;
548//BS_TEXT, BS_BITMAP, BS_ICON, BS_MINIICON can only be used with BS_PUSHBUTTON
549 *os2class = (int)WC_BUTTON & 0xFFFF;
550 if(style == WINBS_PUSHBUTTON)
551 os2style |= BS_PUSHBUTTON;
552 else
553 if(style == WINBS_DEFPUSHBUTTON)
554 os2style |= (BS_PUSHBUTTON | BS_DEFAULT); //TODO: Correct?
555 else
556 if(style == WINBS_CHECKBOX)
557 os2style |= BS_CHECKBOX;
558 else
559 if(style == WINBS_AUTOCHECKBOX)
560 os2style |= BS_AUTOCHECKBOX;
561 else
562 if(style == WINBS_RADIOBUTTON)
563 os2style |= BS_RADIOBUTTON;
564 else
565 if(style == WINBS_3STATE)
566 os2style |= BS_3STATE;
567 else
568 if(style == WINBS_AUTO3STATE)
569 os2style |= BS_AUTO3STATE;
570 else
571 if(style == WINBS_USERBUTTON) //obsolete
572 os2style |= BS_USERBUTTON;
573 else
574 if(style == WINBS_AUTORADIOBUTTON)
575 os2style |= BS_AUTORADIOBUTTON;
576 else
577 if(style == WINBS_GROUPBOX) {
578 *os2class = (int)WC_STATIC & 0xFFFF; /*PLF Sat 97-09-20 23:58:28*/
579 os2style |= SS_GROUPBOX; /*PLF Sun 97-09-21 00:11:07*/
580 }
581 else
582 if(style & WINBS_OWNERDRAW)
583 os2style |= BS_USERBUTTON; //TODO:Correct??
584 else os2style |= (BS_TEXT | BS_PUSHBUTTON);
585 os2style |= BS_AUTOSIZE;
586 break;
587
588 case WIN_EDIT:
589 /* @@@PH 98/06/13: other styles might require a MLE-class control ! */
590 /* please note this is experimental since MLE might behave different from */
591 /* the standard EF-control, maybe we'll have to build an own MLE therefore*/
592
593 if (style & WINES_MULTILINE)
594 {
595 *os2class = (int)WC_MLE & 0xFFFF;
596
597 os2style |= MLS_BORDER | MLS_WORDWRAP;
598
599 //if(style & WINES_MULTILINE) os2style |= ;
600 //if(style & WINES_UPPERCASE) os2style |= ;
601 //if(style & WINES_LOWERCASE) os2style |= ;
602 if(style & WINES_AUTOVSCROLL) os2style |= MLS_VSCROLL;
603 //if(style & WINES_NOHIDESEL) os2style |= ;
604 //if(style & WINES_OEMCONVERT) os2style |= ;
605 //if(style & WINES_WANTRETURN) os2style |= ;
606 //if(style & WINES_LEFT) os2style |= ES_LEFT;
607 //if(style & WINES_CENTER) os2style |= ES_CENTER;
608 //if(style & WINES_RIGHT) os2style |= ES_RIGHT;
609 if(style & WINES_AUTOHSCROLL) os2style |= MLS_HSCROLL;
610 if(style & WINES_READONLY) os2style |= MLS_READONLY;
611 //if(style & WINES_PASSWORD) os2style |= ES_UNREADABLE;
612 }
613 else
614 {
615 *os2class = (int)WC_ENTRYFIELD & 0xFFFF;
616 if(style & WINES_LEFT) os2style |= ES_LEFT;
617 if(style & WINES_CENTER) os2style |= ES_CENTER;
618 if(style & WINES_RIGHT) os2style |= ES_RIGHT;
619 if(style & WINES_AUTOHSCROLL) os2style |= ES_AUTOSCROLL;
620 if(style & WINES_READONLY) os2style |= ES_READONLY;
621 if(style & WINES_PASSWORD) os2style |= ES_UNREADABLE;
622 }
623 break;
624
625 case WIN_STATIC:
626 *os2class = (int)WC_STATIC & 0xFFFF;
627 if(style == WINSS_LEFT)
628 os2style |= SS_TEXT | DT_LEFT;
629 else
630 if(style == WINSS_CENTER)
631 os2style |= SS_TEXT | DT_CENTER;
632 else
633 if(style == WINSS_RIGHT)
634 os2style |= SS_TEXT | DT_RIGHT;
635 else
636 if(style == WINSS_SIMPLE)
637 os2style |= SS_TEXT | DT_LEFT;
638 else
639 if(style == WINSS_ICON) {
640 os2style |= SS_ICON;
641 *fIconBmp = TRUE;
642 }
643 else
644 if(style == WINSS_BLACKRECT)
645 os2style |= SS_FGNDRECT;
646 else
647 if(style == WINSS_GRAYRECT)
648 os2style |= SS_HALFTONERECT;
649 else
650 if(style == WINSS_WHITERECT)
651 os2style |= SS_BKGNDRECT;
652 else
653 if(style == WINSS_BLACKFRAME)
654 os2style |= SS_FGNDFRAME;
655 else
656 if(style == WINSS_GRAYFRAME)
657 os2style |= SS_HALFTONEFRAME;
658 else
659 if(style == WINSS_WHITEFRAME)
660 os2style |= SS_BKGNDFRAME;
661 else os2style |= SS_TEXT;
662
663//TODO
664#if 0
665 if(style == WINSS_LEFTNOWORDWRAP)
666 os2style |= ;
667 if(style == WINSS_USERITEM)
668 os2style |= ;
669 if(style == WINSS_NOPREFIX)
670 os2style |= ;
671#endif
672 break;
673 case WIN_LISTBOX:
674 *os2class = (int)WC_LISTBOX & 0xFFFF;
675#if 0
676 if(style & WINLBS_NOTIFY)
677 os2style |= ;
678 if(style & WINLBS_SORT)
679 os2style |= ;
680 if(style & WINLBS_NOREDRAW)
681 os2style |= ;
682#endif
683 if(style & WINLBS_MULTIPLESEL)
684 os2style |= LS_MULTIPLESEL;
685 if(style & WINLBS_OWNERDRAWFIXED)
686 os2style |= LS_OWNERDRAW; //TODO: Correct?
687 if(style & WINLBS_OWNERDRAWVARIABLE)
688 os2style |= LS_OWNERDRAW; //TODO: Correct?
689#if 0
690 if(style & WINLBS_HASSTRINGS)
691 os2style |= ;
692 if(style & WINLBS_USETABSTOPS)
693 os2style |= ;
694 if(style & WINLBS_NOINTEGRALHEIGHT)
695 os2style |= ;
696 if(style & WINLBS_MULTICOLUMN)
697 os2style |= ;
698 if(style & WINLBS_WANTKEYBOARDINPUT)
699 os2style |= ;
700 if(style & WINLBS_EXTENDEDSEL)
701 os2style |= LS_EXTENDEDSEL;
702 if(style & WINLBS_DISABLENOSCROLL)
703 os2style |= ;
704#endif
705// if(style & WINLBS_NODATA)
706// os2style |= ;
707 break;
708
709 case WIN_SCROLLBAR:
710 *os2class = (int)WC_SCROLLBAR & 0xFFFF;
711
712 if(style & WINSBS_HORZ) os2style |= SBS_HORZ;
713 else
714 if(style & WINSBS_VERT) os2style |= SBS_VERT;
715
716 //if(style & WINSBS_TOPALIGN) os2style |= ;
717 //if(style & WINSBS_LEFTALIGN) os2style |= ;
718 //if(style & WINSBS_BOTTOMALIGN) os2style |= ;
719 //if(style & WINSBS_RIGHTALIGN) os2style |= ;
720 //if(style & WINSBS_SIZEBOXTOPLEFTALIGN) os2style |= ;
721 //if(style & WINSBS_SIZEBOXBOTTOMRIGHTALIGN) os2style |= ;
722
723 if(style & WINSBS_SIZEBOX) os2style |= SBS_AUTOSIZE; //TODO: Correct?
724 break;
725
726 case WIN_COMBOBOX:
727 *os2class = (int)WC_COMBOBOX & 0xFFFF;
728
729 /* @@@PH 98/06/13 corrected style translation */
730 switch (style & 0x00000003)
731 {
732 case WINCBS_SIMPLE: os2style |= CBS_SIMPLE; break;
733 case WINCBS_DROPDOWN: os2style |= CBS_DROPDOWN; break;
734 case WINCBS_DROPDOWNLIST: os2style |= CBS_DROPDOWNLIST; break;
735 default: os2style |= CBS_SIMPLE; break;
736 }
737
738 //if(style & WINCBS_OWNERDRAWFIXED) os2style |= ;
739 //if(style & WINCBS_OWNERDRAWVARIABLE) os2style |= ;
740 //if(style & WINCBS_AUTOHSCROLL) os2style |= ;
741 //if(style & WINCBS_OEMCONVERT) os2style |= ;
742 //if(style & WINCBS_SORT) os2style |= ;
743 //if(style & WINCBS_HASSTRINGS ) os2style |= ;
744 //if(style & WINCBS_NOINTEGRALHEIGHT) os2style |= ;
745 //if(style & WINCBS_DISABLENOSCROLL) os2style |= ;
746 break;
747
748 default:
749 //SvL: 9nov97 Special class control. Just copy style
750 os2style = style;
751 break;
752 }
753 return(os2style);
754}
755
756//******************************************************************************
757//******************************************************************************
758static int ConvertDlgStyle(int style)
759{
760 int os2style = 0;
761
762/// if(style & WINWS_POPUP)
763/// os2style |=
764/// if(style & WINWS_CHILD)
765/// os2style |=
766 if(style & WINWS_MINIMIZE)
767 os2style |= WS_MINIMIZED;
768 if(style & WINWS_MAXIMIZE)
769 os2style |= WS_MAXIMIZED;
770 if(style & WINWS_VISIBLE)
771 os2style |= WS_VISIBLE;
772 if(style & WINWS_DISABLED)
773 os2style |= WS_DISABLED;
774 if(style & WINWS_CLIPSIBLINGS)
775 os2style |= WS_CLIPSIBLINGS;
776 if(style & WINWS_CLIPCHILDREN)
777 os2style |= WS_CLIPCHILDREN;
778 if(style & WINWS_TABSTOP)
779 os2style |= WS_TABSTOP;
780
781 return(os2style);
782}
783//******************************************************************************
784//******************************************************************************
785static int ConvertDlgItemStyle(int style)
786{
787 int os2style = 0;
788
789 if(style & WINWS_VISIBLE)
790 os2style |= WS_VISIBLE;
791 if(style & WINWS_DISABLED)
792 os2style |= WS_DISABLED;
793 if(style & WINWS_CLIPSIBLINGS)
794 os2style |= WS_CLIPSIBLINGS;
795 if(style & WINWS_CLIPCHILDREN)
796 os2style |= WS_CLIPCHILDREN;
797 if(style & WINWS_TABSTOP)
798 os2style |= WS_TABSTOP;
799 if(style & WINWS_GROUP)
800 os2style |= WS_GROUP;
801
802 return(os2style);
803}
804//******************************************************************************
805//******************************************************************************
806static void ConvertCaption(ULONG style, char *caption)
807{
808 char os2caption[512];
809 int i, len = strlen(caption), j;
810
811 switch(style) {
812 case WIN_BUTTON:
813 case WIN_EDIT:
814 case WIN_LISTBOX:
815 case WIN_SCROLLBAR:
816 case WIN_COMBOBOX:
817 for(i=0;i<len;i++) {
818 if(caption[i] == '&') caption[i] = '~';
819 }
820 break;
821 case WIN_STATIC:
822 j = 0;
823 for(i=0;i<=len;i++) {
824 if(caption[i] != '&') os2caption[j++] = caption[i];
825 }
826 strcpy(caption, os2caption);
827 break;
828 }
829}
830//******************************************************************************
831//******************************************************************************
832static int ConvertFont(char *font, PRESPARAMS *dlgpparam, int fsize)
833{
834#if 0
835// if(strcmp(font, "MS SHELL DLG") == 0) {
836 sprintf(dlgpparam->aparam[0].ab, "%d.", fsize);
837// strcat(dlgpparam->aparam[0].ab, font);
838 strcat(dlgpparam->aparam[0].ab, "Helv");
839 return(TRUE);
840// }
841// else TODO: More fonts!!!
842// return(FALSE); //not found
843#else
844 return(FALSE);
845#endif
846}
847//******************************************************************************
848//******************************************************************************
Note: See TracBrowser for help on using the repository browser.