static Bool WdeAddStyleString( char **text, char *str ) { int slen; int tlen; if( text == NULL || str == NULL ) { return( FALSE ); } slen = strlen( str ); if( *text == NULL ) { *text = WdeMemAlloc( slen + 1 ); if( *text != NULL ) { strcpy( *text, str ); } } else { tlen = strlen( *text ); tlen += slen + 3 + 1; *text = (char *)WdeMemRealloc( *text, tlen ); if( *text != NULL ) { strcat( *text, " | " ); strcat( *text, str ); } } return( *text != NULL ); }
Bool WdeSetMemFlagsText( uint_16 flags, char **text ) { int tlen; if( text == NULL ) { return( FALSE ); } tlen = 0; *text = NULL; if( flags & MEMFLAG_PRELOAD ) { tlen += 8; // size of the string PRELOAD and a space } if( !(flags & MEMFLAG_MOVEABLE) ) { tlen += 6; // size of the string FIXED and a space } if( flags & MEMFLAG_DISCARDABLE ) { tlen += 12; // size of the string DISCARDABLE and a space } if( !(flags & MEMFLAG_PURE) ) { tlen += 7; // size of the string IMPURE and a space } if( tlen == 0 ) { return( TRUE ); } *text = (char *)WdeMemAlloc( tlen + 1 ); if( *text == NULL ) { return( FALSE ); } (*text)[0] = '\0'; if( flags & MEMFLAG_PRELOAD ) { strcat( *text, "PRELOAD " ); } if( !(flags & MEMFLAG_MOVEABLE) ) { strcat( *text, "FIXED " ); } if( flags & MEMFLAG_DISCARDABLE ) { strcat( *text, "DISCARDABLE " ); } if( !(flags & MEMFLAG_PURE) ) { strcat( *text, "IMPURE " ); } return( TRUE ); }
void *MemAlloc ( unsigned size ) { void *p; p = WdeMemAlloc ( size ); if ( p ) { memset ( p, 0, size ); } return ( p ); }
char *WdeStrDup( const char *src ) { char *dest; if( src == NULL ) { return( NULL ); } dest = WdeMemAlloc( strlen( src ) + 1 ); if( dest != NULL ) { strcpy( dest, src ); } return( dest ); }
WdeCustControl *WdeAllocCustControl ( void ) { WdeCustControl *control; control = (WdeCustControl *) WdeMemAlloc ( sizeof(WdeCustControl) ); if ( control == NULL ) { WdeWriteTrail("WdeAllocCustControl: WdeCustControl alloc failed!"); return ( NULL ); } memset ( control, 0, sizeof(WdeCustControl) ); return ( control ); }
WdeCustLib *WdeAllocCustLib ( void ) { WdeCustLib *lib; lib = (WdeCustLib *) WdeMemAlloc ( sizeof(WdeCustLib) ); if ( lib == NULL ) { WdeWriteTrail("WdeAllocCustLib: WdeCustLib alloc failed!"); return ( NULL ); } memset ( lib, 0, sizeof(WdeCustLib) ); WdeMemValidate ( lib ); return ( lib ); }
static Bool WdeSetDefaultTestControlEntries( HWND win ) { int index; char *text; char *str; char cname[20]; int len; uint_8 class; len = GetClassName( win, cname, 19 ); if( len == 0 ) { return( TRUE ); } class = WdeGetClassFromClassName( cname ); if( class == CLASS_LISTBOX || class == CLASS_COMBOBOX ) { str = NULL; text = WdeAllocRCString( WDE_TESTITEM ); if( text != NULL ) { str = (char *)WdeMemAlloc( strlen( text ) + 10 + 1 ); if( str == NULL ) { WdeFreeRCString( text ); return( TRUE ); } } else { return( TRUE ); } SendMessage( win, WM_SETREDRAW, FALSE, 0 ); for( index = 1; index <= TEST_DEFAULT_ENTRIES; index++ ) { sprintf( str, text, index ); if( class == CLASS_LISTBOX ) { SendMessage( win, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)str ); } else { SendMessage( win, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)str ); } } SendMessage( win, WM_SETREDRAW, TRUE, 0 ); InvalidateRect( win, NULL, TRUE ); WdeMemFree( str ); WdeFreeRCString( text ); }
BOOL WdeLoadMSCustomControls( WdeCustLib *lib ) { LPFNCCINFO info_proc; UINT num_classes; info_proc = (LPFNCCINFO)GetProcAddress( lib->inst, "CustomControlInfoA" ); if( info_proc == NULL ) { info_proc = (LPFNCCINFO)GetProcAddress( lib->inst, "CustomControlInfoW" ); if( info_proc == NULL ) { WdeWriteTrail( "WdeLoadMSCustomControls: Info Proc not found!" ); } else { WdeSetStatusByID( -1, WDE_UNICUSTNOTSUPPORTED ); } return( FALSE ); } num_classes = (*info_proc)( NULL ); if( num_classes == 0 ) { WdeWriteTrail( "WdeLoadMSCustomControls: Info Proc returned NULL!" ); return( FALSE ); } lib->lpcci = (LPCCINFO)WdeMemAlloc( sizeof( CCINFO ) * num_classes ); if( lib->lpcci == NULL ) { WdeWriteTrail( "WdeLoadMSCustomControls: LPCCINFO alloc failed!" ); return( FALSE ); } memset( lib->lpcci, 0, sizeof( CCINFO ) * num_classes ); lib->num_classes = (*info_proc)( lib->lpcci ); if( lib->num_classes != num_classes ) { WdeWriteTrail( "WdeLoadMSCustomControls: LPCCINFO inconsistent!" ); } return( TRUE ); }
Bool WdeCreateWdePopupListItem( int num, HMENU menu, WdePopupHintItem *hint_items ) { WdePopupListItem *p; p = (WdePopupListItem *)WdeMemAlloc( sizeof( WdePopupListItem ) ); if( p != NULL ) { p->num = num; p->menu = menu; p->hint_items = hint_items; if( WdeInitHintItems( num, menu, hint_items ) ) { ListAddElt( &WdePopupList, p ); } else { WdeMemFree( p ); return( FALSE ); } } else { return( FALSE ); } return( TRUE ); }
void WdeDisplayHint( int id ) { char *buf; char *mditext; WdeHintItem *hint; if( id < WDE_MDI_FIRST ) { hint = WdeGetHintItem( id ); if( hint != NULL ) { WdeSetStatusByID( -1, hint->hint ); } } else { mditext = WdeAllocRCString( WDE_HINT_MDIMSG ); if( mditext != NULL ) { buf = WdeMemAlloc( strlen( mditext ) + 20 + 1 ); if( buf != NULL ) { sprintf( buf, mditext, WDE_MDI_FIRST + 1 - id ); WdeSetStatusText( NULL, buf, TRUE ); WdeMemFree( buf ); } WdeFreeRCString( mditext ); } } }
BOOL WdeLoadBorCustomControls ( WdeCustLib *lib ) { WdeListClassesProc list_proc; HGLOBAL list_global; uint_8 *list_locked; uint_16 num_classes; WdeBorlandClassList *class_list; uint_32 class_list_size; /* touch unused var to get rid of warning */ _wde_touch( lib ); list_proc = (WdeListClassesProc) GetProcAddress(lib->inst, "ListClasses"); if ( list_proc == NULL ) { if ( WdeQueryAssumeMS () ) { lib->ms_lib = TRUE; return ( WdeLoadMSCustomControls ( lib ) ); } else { WdeWriteTrail("WdeLoadBorCustomControls: User aborted load!"); return ( FALSE ); } } if ( WdeCustLOADRESInst == NULL ) { WdeCustLOADRESInst = MakeProcInstance ( (FARPROC) WdeCustLOADRES, WdeGetAppInstance() ); } if ( WdeCustEDITRESInst == NULL ) { WdeCustEDITRESInst = MakeProcInstance ( (FARPROC) WdeCustEDITRES, WdeGetAppInstance() ); } #if 0 list_global = (*list_proc) ( "WdeMainClass", WDE_VERSION, (LPFNLOADRES) WdeCustLOADRES, (LPFNEDITRES) WdeCustEDITRES ); #else list_global = (*list_proc) ( "WdeMainClass", WDE_VERSION, (LPFNLOADRES) WdeCustLOADRESInst, (LPFNEDITRES) WdeCustEDITRESInst ); #endif if ( list_global == NULL ) { WdeWriteTrail("WdeLoadBorCustomControls: ListClasses returned NULL!"); return ( FALSE ); } list_locked = (uint_8 *) GlobalLock ( list_global ); if ( list_locked == NULL ) { WdeWriteTrail("WdeLoadBorCustomControls: Could lock global memory!"); GlobalFree( list_global ); return ( FALSE ); } num_classes = *((uint_16 *) list_locked); class_list_size = sizeof(WdeBorlandClassList) + (num_classes-1) * sizeof(WdeBorlandCtlClass); class_list = ( WdeBorlandClassList *) WdeMemAlloc ( class_list_size ); if ( class_list == NULL ) { WdeWriteTrail("WdeLoadBorCustomControls: class list alloc failed!"); GlobalUnlock ( list_global ); GlobalFree( list_global ); return ( FALSE ); } memcpy ( class_list, list_locked, class_list_size ); lib->class_list = list_global; if ( !WdeAddBorControlsToCustLib ( lib, class_list ) ) { WdeWriteTrail("WdeLoadBorCustomControls: Add to CustLib failed!"); WdeMemFree ( class_list ); GlobalUnlock ( list_global ); GlobalFree ( list_global ); return ( FALSE ); } WdeMemFree ( class_list ); GlobalUnlock ( list_global ); WdeMemValidate ( lib ); return ( TRUE ); }
WdeDialogBoxInfo *WdeMem2DBI( uint_8 *data, uint_32 size, Bool is32bit ) { WdeDialogBoxInfo *dbi; WdeDialogBoxControl *control; LIST *prev_control; int index, pad; uint_8 *d; Bool ok; Bool is32bitEx = FALSE; uint_16 signa[2]; dbi = NULL; ok = ( data && size ); if( ok ) { d = data; dbi = (WdeDialogBoxInfo *) WdeMemAlloc( sizeof(WdeDialogBoxInfo) ); ok = ( dbi != NULL ); } if( ok ) { /* check if the dialog is extended by testing for the signature */ memcpy(signa, data, sizeof(signa)); is32bitEx = (signa[0] == 0x0001 && signa[1] == 0xFFFF); dbi->control_list = NULL; dbi->MemoryFlags = 0; if (is32bitEx) { dbi->dialog_header = WdeMem2DialogBoxExHeader( &data ); } else { dbi->dialog_header = WdeMem2DialogBoxHeader( &data, is32bit ); } ok = ( dbi->dialog_header != NULL ); } if( ok ) { prev_control = NULL; for( index = 0; index < GETHDR_NUMITEMS(dbi->dialog_header); index++ ) { if( is32bit ) { pad = CALC_PAD( data - d, sizeof(uint_32) ); data += pad; } control = WdeMem2DialogBoxControl( &data, is32bit, is32bitEx ); if( control == NULL ) { ok = FALSE; break; } if ( prev_control == NULL ) { ListAddElt( &(dbi->control_list), (void *) control); prev_control = dbi->control_list; } else { ListInsertElt( prev_control, (void *) control); prev_control = ListNext(prev_control); } } } if( ok ) { ok = ( size >= ( data - d ) ); } if( !ok ) { if( dbi ) { WdeFreeDialogBoxInfo( dbi ); dbi = NULL; } } return ( dbi ); }
Bool WdeDBI2Mem( WdeDialogBoxInfo *info, uint_8 **mem, uint_32 *size ) { Bool ok; uint_32 pos, memsize, sz, pad; LIST *l; WdeDialogBoxControl *ci; Bool is32bit; Bool is32bitEx; is32bit = info->dialog_header->is32bit; is32bitEx = info->dialog_header->is32bitEx; ok = ( info && mem && size ); if( ok ) { *mem = NULL; memsize = (int) WdeCalcSizeOfWdeDialogBoxInfo( info ); ok = ( memsize != 0 ); } if( ok ) { *mem = WdeMemAlloc( memsize ); ok = ( *mem != NULL ); } if( ok ) { if( is32bit && is32bitEx ) { pos = WdeDialogBoxExHeaderToMem( info->dialog_header, *mem ); } else { pos = WdeDialogBoxHeaderToMem( info->dialog_header, *mem ); } ok = ( pos != 0 ); } if( ok ) { for ( l = info->control_list; l; l = ListNext(l) ) { ci = ListElement ( l ); if( ci == NULL ) { ok = FALSE; break; } if( is32bit ) { pad = CALC_PAD( pos, sizeof(uint_32) ); memset( (*mem)+pos, 0, pad ); pos += pad; } sz = WdeDialogBoxControlToMem( ci, (*mem)+pos, is32bit, is32bitEx ); if( sz == 0 ) { ok = FALSE; break; } pos += sz; } } if( is32bit ) { pad = CALC_PAD( pos, sizeof(uint_32) ); memset( (*mem)+pos, 0, pad ); pos += pad; } if ( ok ) { ok = ( pos == memsize ); if ( ok ) { *size = memsize; } } else { if ( mem && *mem ) { WdeMemFree ( *mem ); *mem = NULL; } } return ( ok ); }
Bool WdeCreateResourceWindow( WdeResInfo *res_info, int fn_offset, char *title ) { MDICREATESTRUCT mdics; LRESULT ret; HWND win; Bool ok; Bool old; DWORD style; RECT r; HMENU sys_menu; char *win_title; int win_title_len; _wde_touch( fn_offset ); WdeIncNumRes(); style = 0; if( WdeGetNumRes() == 1 ) { WdeSetAppMenuToRes( TRUE ); old = WdeSetStickyMode( WdeOldStickyMode ); style = WS_MAXIMIZE; } else { if( WdeIsCurrentMDIWindowZoomed() ) { style = WS_MAXIMIZE; } } mdics.szClass = "WdeResClass"; win_title = NULL; if( title == NULL ) { if( res_info->info->file_name ) { // perhaps make this an option //title = &res_info->info->file_name[fn_offset]; mdics.szTitle = res_info->info->file_name; } else { WdeResCounter++; win_title_len = strlen( WdeResUntitled ) + 7; win_title = (char *)WdeMemAlloc( win_title_len ); sprintf( win_title, "%s.%d", WdeResUntitled, 0xffff & WdeResCounter ); mdics.szTitle = win_title; } } else { mdics.szTitle = title; } win = WdeGetMDIWindowHandle(); GetClientRect( win, &r ); mdics.hOwner = WdeGetAppInstance(); mdics.x = CW_USEDEFAULT; mdics.y = CW_USEDEFAULT; mdics.cx = CW_USEDEFAULT; mdics.cy = CW_USEDEFAULT; //mdics.cx = r.right - r.left; //mdics.cy = r.bottom - r.top; mdics.style = style; mdics.lParam = (LPARAM)res_info; ret = SendMessage( win, WM_MDICREATE, 0, (LPARAM)&mdics ); if( win_title != NULL ) { WdeMemFree( win_title ); } #ifdef __NT__ win = (HWND)ret; #else win = (HWND)LOWORD( ret ); #endif ok = (res_info->res_win != NULL && res_info->res_win == win); if( !ok ) { WdeWriteTrail( "WdeCreateResourceWindow: Bad window handle!" ); } if( WdeIsDDE() ) { sys_menu = GetSystemMenu( win, FALSE ); if( sys_menu != (HMENU)NULL ) { EnableMenuItem( sys_menu, SC_CLOSE, MF_GRAYED ); } } if( ok ) { ok = WdeCreateEditWindows( res_info ); if( !ok ) { WdeWriteTrail( "WdeCreateResourceWindow: Could not create edit windows!" ); } } if( ok ) { OpenFormEdit( res_info->forms_win, WdeGetCreateTable(), MENU_NONE, SCROLL_NONE ); WdeSetEditMode( res_info, TRUE ); SetHorizontalInc( 1 ); SetVerticalInc( 1 ); InitState( res_info->forms_win ); SetMouseRtn( res_info->forms_win, WdeMouseRtn ); //MakeObjectCurrent( GetMainObject() ); } else { if( WdeGetNumRes() == 1 ) { WdeSetAppMenuToRes( FALSE ); WdeSetStickyMode( old ); } WdeDecNumRes(); } return( ok ); }
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 file; WdeDialogBoxControl *control; LIST *prev_control; #if 0 WdeDialogBoxControl *nc; LIST *clist; #endif int index; char *file_name; Bool ok; dlg_info = NULL; file = -1; ok = (res_info != NULL && lnode != NULL); if( ok ) { file_name = res_info->info->tmp_file; dlg_info = (WdeDialogBoxInfo *)WdeMemAlloc( 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; file = ResOpenFileRO( file_name ); ok = (file != -1); } if( ok ) { dlg_info->MemoryFlags = lnode->Info.MemoryFlags; ok = (lseek( file, lnode->Info.Offset, SEEK_SET ) != -1); } if( ok ) { if( is32bit ) { /* JPK - check if its an extended dialog */ dlg_info->dialog_header->is32bitEx = ResIsDialogEx( file ); lseek( file, lnode->Info.Offset, SEEK_SET ); if( dlg_info->dialog_header->is32bitEx ) { ok = !ResReadDialogExHeader32( &h32, &h32ex, file ); } else { ok = !ResReadDialogBoxHeader32( &h32, file ); } } else { ok = !ResReadDialogBoxHeader( &h16, file ); } } 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->HelpId = h32ex.HelpId; dlg_info->dialog_header->FontWeightDefined = (h32ex.FontWeightDefined != 0); dlg_info->dialog_header->FontItalicDefined = (h32ex.FontItalicDefined != 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, file ) ) { 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, file ) ) { 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, file ) ) { 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->HelpId = 0; dlg_info->dialog_header->FontWeightDefined = FALSE; dlg_info->dialog_header->FontItalicDefined = FALSE; /* now deal with the list of controls */ nc = (WdeDialogBoxControl *)WdeMemAlloc( 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 ) ); } WdeMemFree( nc ); } #endif if( !ok ) { if( dlg_info != NULL ) { WdeFreeDialogBoxInfo( dlg_info ); dlg_info = NULL; } } if( file != -1 ) { ResCloseFile( file ); } return( dlg_info ); }