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

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

Dialog box conversion bugfix for entryfields

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