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

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

Include os2wrap.h instead of os2.h

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