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