source: trunk/src/user32/dlgconvert.cpp@ 265

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

Dialog changes + fixes

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