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