WdeDialogBoxHeader *WdeMem2DialogBoxHeader( const uint_8 **pdata, bool is32bit, bool is32bitEx ) { WdeDialogBoxHeader *dbh; bool ok; const uint_8 *data; dbh = NULL; data = NULL; ok = (pdata != NULL && *pdata != NULL); if( ok ) { dbh = WdeAllocDialogBoxHeader(); ok = (dbh != NULL); } if( ok ) { data = *pdata; dbh->symbol = NULL; dbh->helpsymbol = NULL; dbh->is32bit = is32bit; dbh->is32bitEx = is32bitEx; if( is32bitEx ) { /* skip the miscellaneous two WORDs 0x0001, 0xFFFF */ data += 2 * sizeof( uint_16 ); U32FromMem( data, GETHDR_HELPID( dbh ) ); U32FromMem( data, GETHDR_EXSTYLE( dbh ) ); U32FromMem( data, GETHDR_STYLE( dbh ) ); } else if( is32bit ) { U32FromMem( data, GETHDR_STYLE( dbh ) ); U32FromMem( data, GETHDR_EXSTYLE( dbh ) ); } else { U32FromMem( data, GETHDR_STYLE( dbh ) ); } if( is32bit ) { U16FromMem( data, GETHDR_NUMITEMS( dbh ) ); } else { U8FromMem( data, GETHDR_NUMITEMS( dbh ) ); } U16FromMem( data, GETHDR_SIZEX( dbh ) ); U16FromMem( data, GETHDR_SIZEY( dbh ) ); U16FromMem( data, GETHDR_SIZEW( dbh ) ); U16FromMem( data, GETHDR_SIZEH( dbh ) ); SETHDR_MENUNAME( dbh, WdeMem2NameOrOrdinal( &data, is32bit ) ); ok = (GETHDR_MENUNAME( dbh ) != NULL); } if( ok ) { SETHDR_CLASSNAME( dbh, WdeMem2NameOrOrdinal( &data, is32bit ) ); ok = (GETHDR_CLASSNAME( dbh ) != NULL); } if( ok ) { SETHDR_CAPTION( dbh, WdeMem2String( &data, is32bit ) ); ok = (GETHDR_CAPTION( dbh ) != NULL); } if( ok ) { if( GETHDR_STYLE( dbh ) & DS_SETFONT ) { U16FromMem( data, GETHDR_POINTSIZE( dbh ) ); if( is32bitEx ) { U16FromMem( data, GETHDR_FONTWEIGHT( dbh ) ); U8FromMem( data, GETHDR_FONTITALIC( dbh ) ); U8FromMem( data, GETHDR_FONTCHARSET( dbh ) ); } SETHDR_FONTNAME( dbh, WdeMem2String( &data, is32bit ) ); ok = (GETHDR_FONTNAME( dbh ) != NULL); } else { SETHDR_POINTSIZE( dbh, 0 ); SETHDR_FONTNAME( dbh, NULL ); } } if( dbh != NULL ) { *pdata = data; if( !ok ) { WdeFreeDialogBoxHeader( &dbh ); } } return( dbh ); }
WdeDialogBoxHeader *WdeMem2DialogBoxHeader( uint_8 **data, Bool is32bit ) { DialogBoxHeader32 *h32; DialogBoxHeader *h16; WdeDialogBoxHeader *dbh; int fixedbytes; Bool ok; dbh = NULL; ok = ( data && *data ); if( ok ) { dbh = WdeAllocDialogBoxHeader(); ok = ( dbh != NULL ); } if( ok ) { dbh->symbol = NULL; dbh->helpsymbol = NULL; dbh->is32bit = is32bit; dbh->is32bitEx = FALSE; if( is32bit ) { fixedbytes = offsetof( DialogBoxHeader32, MenuName ); h32 = (DialogBoxHeader32 *)*data; dbh->Style = h32->Style; dbh->ExtendedStyle = h32->ExtendedStyle; dbh->NumOfItems = h32->NumOfItems; dbh->Size = h32->Size; } else { fixedbytes = offsetof( DialogBoxHeader, MenuName ); h16 = (DialogBoxHeader *)*data; dbh->Style = h16->Style; dbh->NumOfItems = h16->NumOfItems; dbh->Size = h16->Size; } *data += fixedbytes; SETHDR_MENUNAME(dbh, WdeMem2NameOrOrdinal( data, is32bit ) ); ok = ( GETHDR_MENUNAME(dbh) != NULL ); } if( ok ) { SETHDR_CLASSNAME( dbh, WdeMem2NameOrOrdinal( data, is32bit ) ); ok = ( GETHDR_CLASSNAME(dbh) != NULL ); } if( ok ) { SETHDR_CAPTION( dbh, WdeMem2String( data, is32bit ) ); ok = ( GETHDR_CAPTION(dbh) != NULL ); } if( ok ) { if( GETHDR_STYLE(dbh) & DS_SETFONT ) { SETHDR_POINTSIZE( dbh, *( (uint_16 *)*data ) ); *data += sizeof(uint_16); SETHDR_FONTNAME( dbh, WdeMem2String( data, is32bit ) ); ok = ( GETHDR_FONTNAME(dbh) != NULL ); } else { SETHDR_POINTSIZE( dbh, 0 ); SETHDR_FONTNAME( dbh, NULL ); } } if( !ok ) { if( dbh ) { WdeFreeDialogBoxHeader ( &dbh ); } } return( dbh ); }
WdeDialogBoxHeader *WdeMem2DialogBoxExHeader( uint_8 **data ) { uint_16 miscbytes[2] = { 0x0001, 0xFFFF }; WdeDialogBoxHeader *dbh; Bool ok; dbh = NULL; if ( !data || !*data ) { return(NULL); } dbh = WdeAllocDialogBoxHeader(); if ( dbh == NULL ) { return(NULL); } dbh->is32bit = TRUE; dbh->is32bitEx = TRUE; /* skip the miscellaneous two WORDs 01 00 FF FF */ *data += sizeof(miscbytes); memcpy( &dbh->HelpId, *data, sizeof(uint_32) ); *data += sizeof(uint_32); memcpy( &dbh->ExtendedStyle, *data, sizeof(uint_32) ); *data += sizeof(uint_32); memcpy( &dbh->Style, *data, sizeof(uint_32) ); *data += sizeof(uint_32); memcpy( &dbh->NumOfItems, *data, sizeof(uint_16) ); *data += sizeof(uint_16); memcpy( &dbh->Size, *data, sizeof(DialogSizeInfo) ); *data += sizeof(DialogSizeInfo); SETHDR_MENUNAME(dbh, WdeMem2NameOrOrdinal( data, TRUE ) ); ok = ( GETHDR_MENUNAME(dbh) != NULL ); if( ok ) { SETHDR_CLASSNAME( dbh, WdeMem2NameOrOrdinal( data, TRUE ) ); ok = ( GETHDR_CLASSNAME(dbh) != NULL ); } if( ok ) { SETHDR_CAPTION( dbh, WdeMem2String( data, TRUE ) ); ok = ( GETHDR_CAPTION(dbh) != NULL ); } if( ok ) { if( GETHDR_STYLE(dbh) & DS_SETFONT ) { dbh->FontWeightDefined = TRUE; dbh->FontItalicDefined = TRUE; SETHDR_POINTSIZE( dbh, *((uint_16 *)*data) ); *data += sizeof(uint_16); SETHDR_FONTWEIGHT( dbh, *((uint_16 *)*data) ); *data += sizeof(uint_16); SETHDR_FONTITALIC( dbh, *((uint_16 *)*data) ); *data += sizeof(uint_16); SETHDR_FONTNAME( dbh, WdeMem2String( data, TRUE ) ); ok = ( GETHDR_FONTNAME(dbh) != NULL ); } } if( !ok ) { if( dbh ) { WdeFreeDialogBoxHeader ( &dbh ); } } return( dbh ); }
WdeDialogBoxInfo *WdeLoadDialogFromRes( WdeResInfo *res_info, WResLangNode *lnode, bool is32bit ) { DialogExHeader32 h32ex; DialogBoxHeader32 h32; DialogBoxHeader h16; DialogBoxControl c16; DialogBoxControl32 c32; DialogBoxExControl32 c32ex; WdeDialogBoxInfo *dlg_info; WResFileID fid; WdeDialogBoxControl *control; LIST *prev_control; #if 0 WdeDialogBoxControl *nc; LIST *clist; #endif int index; char *file_name; bool ok; dlg_info = NULL; fid = WRES_NIL_HANDLE; ok = (res_info != NULL && lnode != NULL); if( ok ) { file_name = res_info->info->tmp_file; dlg_info = (WdeDialogBoxInfo *)WRMemAlloc( sizeof( WdeDialogBoxInfo ) ); ok = (dlg_info != NULL); } if( ok ) { dlg_info->dialog_header = WdeAllocDialogBoxHeader(); ok = (dlg_info->dialog_header != NULL); } if( ok ) { dlg_info->dialog_header->is32bit = is32bit; dlg_info->control_list = NULL; dlg_info->MemoryFlags = 0; ok = ((fid = ResOpenFileRO( file_name )) != WRES_NIL_HANDLE); } if( ok ) { dlg_info->MemoryFlags = lnode->Info.MemoryFlags; ok = (ResSeek( fid, lnode->Info.Offset, SEEK_SET ) != -1); } if( ok ) { if( is32bit ) { /* JPK - check if its an extended dialog */ dlg_info->dialog_header->is32bitEx = ResIsDialogEx( fid ); ResSeek( fid, lnode->Info.Offset, SEEK_SET ); if( dlg_info->dialog_header->is32bitEx ) { ok = !ResReadDialogExHeader32( &h32, &h32ex, fid ); } else { ok = !ResReadDialogBoxHeader32( &h32, fid ); } } else { ok = !ResReadDialogBoxHeader( &h16, fid ); } } if( ok ) { if( is32bit ) { if( dlg_info->dialog_header->is32bitEx ) { dlg_info->dialog_header->FontWeight = h32ex.FontWeight; dlg_info->dialog_header->FontItalic = h32ex.FontItalic; dlg_info->dialog_header->FontCharset = h32ex.FontCharset; dlg_info->dialog_header->HelpId = h32ex.HelpId; dlg_info->dialog_header->FontWeightDefined = (h32ex.FontWeightDefined != 0); dlg_info->dialog_header->FontItalicDefined = (h32ex.FontItalicDefined != 0); dlg_info->dialog_header->FontCharsetDefined = (h32ex.FontCharsetDefined != 0); } dlg_info->dialog_header->Style = h32.Style; dlg_info->dialog_header->ExtendedStyle = h32.ExtendedStyle; dlg_info->dialog_header->NumOfItems = h32.NumOfItems; dlg_info->dialog_header->Size = h32.Size; dlg_info->dialog_header->MenuName = h32.MenuName; dlg_info->dialog_header->ClassName = h32.ClassName; dlg_info->dialog_header->Caption = h32.Caption; dlg_info->dialog_header->PointSize = h32.PointSize; dlg_info->dialog_header->FontName = h32.FontName; } else { dlg_info->dialog_header->Style = h16.Style; dlg_info->dialog_header->NumOfItems = h16.NumOfItems; dlg_info->dialog_header->Size = h16.Size; dlg_info->dialog_header->MenuName = h16.MenuName; dlg_info->dialog_header->ClassName = h16.ClassName; dlg_info->dialog_header->Caption = h16.Caption; dlg_info->dialog_header->PointSize = h16.PointSize; dlg_info->dialog_header->FontName = h16.FontName; } prev_control = NULL; for( index = 0; index < GETHDR_NUMITEMS( dlg_info->dialog_header ); index++ ) { control = WdeAllocDialogBoxControl(); if( control == NULL ) { ok = false; break; } if( is32bit ) { /* * JPK - check which control structure to expect based on * whether this an extended dialog or not */ if( dlg_info->dialog_header->is32bitEx ) { if( ResReadDialogExControl32( &c32ex, fid ) ) { ok = false; break; } control->HelpId = c32ex.HelpId; control->ExtendedStyle = c32ex.ExtendedStyle; control->Style = c32ex.Style; control->Size = c32ex.Size; control->ID = c32ex.ID; control->ClassID = c32ex.ClassID; control->Text = c32ex.Text; control->ExtraBytes = c32ex.ExtraBytes; } else { if( ResReadDialogBoxControl32( &c32, fid ) ) { ok = false; break; } control->Style = c32.Style; control->ExtendedStyle = c32.ExtendedStyle; control->Size = c32.Size; control->ID = c32.ID; control->ClassID = c32.ClassID; control->Text = c32.Text; control->ExtraBytes = c32.ExtraBytes; } } else { if( ResReadDialogBoxControl( &c16, fid ) ) { ok = false; break; } control->Size = c16.Size; control->ID = c16.ID; control->Style = c16.Style; control->ClassID = c16.ClassID; control->Text = c16.Text; control->ExtraBytes = c16.ExtraBytes; } if ( prev_control == NULL ) { ListAddElt( &dlg_info->control_list, (void *)control ); prev_control = dlg_info->control_list; } else { ListInsertElt( prev_control, (void *)control ); prev_control = ListNext( prev_control ); } } } #if 0 /* * JPK - if the dialog is 32 bit but not EX, then convert the dialog * header and the control list to EX; this will force all * dialogs to EX, for now */ if( is32bit && !dlg_info->dialog_header->is32bitEx ) { /* deal with the dialog header first */ dlg_info->dialog_header->is32bitEx = TRUE; dlg_info->dialog_header->FontWeight = 0; dlg_info->dialog_header->FontItalic = 0; dlg_info->dialog_header->FontCharset = DEFAULT_CHARSET; dlg_info->dialog_header->HelpId = 0; dlg_info->dialog_header->FontWeightDefined = FALSE; dlg_info->dialog_header->FontItalicDefined = FALSE; dlg_info->dialog_header->FontCharsetDefined = FALSE; /* now deal with the list of controls */ nc = (WdeDialogBoxControl *)WRMemAlloc( sizeof( WdeDialogBoxControl ) ); for( clist = dlg_info->control_list; clist != NULL; clist = ListNext( clist ) ) { control = (WdeDialogBoxControl *)ListElement( clist ); memcpy( nc, control, sizeof( WdeDialogBoxControl ) ); nc->HelpId = 0; nc->ExtendedStyle = control->ExtendedStyle; nc->Style = control->Style; memcpy( &nc->Size, &control->Size, sizeof( DialogSizeInfo ) ); nc->ID = control->ID; nc->ClassID = control->ClassID; nc->Text = control->Text; nc->ExtraBytes = control->ExtraBytes; memcpy( control, nc, sizeof( WdeDialogBoxControl ) ); } WRMemFree( nc ); } #endif if( !ok ) { if( dlg_info != NULL ) { WdeFreeDialogBoxInfo( dlg_info ); dlg_info = NULL; } } if( fid != WRES_NIL_HANDLE ) { ResCloseFile( fid ); } return( dlg_info ); }