WdeResInfo *WdeCreateNewResource( char *title ) { WdeResInfo *res_info; bool ok; ok = ((res_info = WdeAllocResInfo()) != NULL); if( ok ) { ok = ((res_info->info = WRAllocWRInfo()) != NULL); } if( ok ) { res_info->hash_table = WRInitHashTable(); ok = (res_info->hash_table != NULL); } if( ok ) { if( title != NULL ) { res_info->info->save_name = WdeStrDup( title ); ok = (res_info->info->save_name != NULL); } } if( ok ) { #ifdef __NT__ res_info->is32bit = TRUE; #else res_info->is32bit = FALSE; #endif ok = WdeCreateResourceWindow( res_info, 0, title ); } if( ok ) { ListAddElt( &WdeResList, (void *)res_info ); if( !WdeIsDDE() || title == NULL ) { ok = (WdeCreateNewDialog( NULL, res_info->is32bit ) != NULL); } } if( ok ) { WdeCheckBaseScrollbars( FALSE ); } if( res_info ) { if( ok ) { WdeSetResModified( res_info, FALSE ); } else { WdeRemoveResource( res_info ); res_info = NULL; } } return( res_info ); }
void WdeResetOpts( void ) { if( WdeCurrentState.inc_path != NULL ) { WRMemFree( WdeCurrentState.inc_path ); } WdeCurrentState.is_wres_fmt = WdeDefaultState.is_wres_fmt; WdeCurrentState.use_def_dlg = WdeDefaultState.use_def_dlg; WdeCurrentState.grid_x = WdeDefaultState.grid_x; WdeCurrentState.grid_y = WdeDefaultState.grid_y; WdeCurrentState.ignore_inc = WdeDefaultState.ignore_inc; WdeCurrentState.inc_path = WdeStrDup( WdeDefaultState.inc_path ); }
static bool WdeGetStrOpt( char *entry, char **opt ) { char str[_MAX_PATH]; bool ret; ret = GetPrivateProfileString( WdeSectionName, entry, "", str, _MAX_PATH - 1, WdeProfileName ); if( ret ) { if( !WdeIsStrSpace( str ) ) { ret = ((*opt = WdeStrDup( str )) != NULL); } } return( ret ); }
void WdeOptsShutdown( void ) { if( WdeCurrentState.last_directory != NULL ) { WRMemFree( WdeCurrentState.last_directory ); } if( WdeCurrentState.last_file_filter != NULL ) { WRMemFree( WdeCurrentState.last_file_filter ); } WdeCurrentState.last_directory = WdeStrDup( WdeGetInitialDir() ); WdeCurrentState.last_file_filter = WdeGetFileFilter(); WdeWriteOpts( &WdeCurrentState ); if( WdeCurrentState.last_directory != NULL ) { WRMemFree( WdeCurrentState.last_directory ); } if( WdeCurrentState.inc_path != NULL ) { WRMemFree( WdeCurrentState.inc_path ); } }
char *WdeGetFileName( WdeGetFileStruct *gf, DWORD flags, WdeGetFileNameAction action ) { OPENFILENAME wdeofn; HWND owner_window; DWORD error; char fn_drive[_MAX_DRIVE]; char fn_dir[_MAX_DIR]; char fn_name[_MAX_FNAME]; char fn_ext[_MAX_EXT]; char ext[_MAX_EXT + 1]; HINSTANCE app_inst; int len; int filter; bool ret; if( gf == NULL ) { return( NULL ); } owner_window = WdeGetMainWindowHandle(); app_inst = WdeGetAppInstance(); if( app_inst == NULL || owner_window == NULL ) { return( NULL ); } /* set the initial directory */ if( *wde_initial_dir == '\0' ) { getcwd( wde_initial_dir, MAXFILENAME ); } if( gf->title != NULL ) { len = strlen( gf->title ); if ( len < MAX_NAME ) { memcpy( wdefntitle, gf->title, len + 1 ); } else { memcpy( wdefntitle, gf->title, MAX_NAME ); wdefntitle[MAX_NAME - 1] = 0; } } else { wdefntitle[0] = 0; } filter = 0; if( gf->file_name != NULL && *gf->file_name != '\0' ) { _splitpath( gf->file_name, fn_drive, fn_dir, fn_name, fn_ext ); if( *fn_drive != '\0' || *fn_dir != '\0' ) { _makepath( wde_initial_dir, fn_drive, fn_dir, NULL, NULL ); } _makepath( wde_file_name, NULL, NULL, fn_name, fn_ext ); if( fn_ext[0] != '\0' ) { ext[0] = '*'; strcpy( ext + 1, fn_ext ); filter = WdeFindFileFilterIndex( gf->filter, ext ); } } else { wde_file_name[0] = 0; } if( filter == 0 ) { filter = WdeFindFileFilterIndex( gf->filter, WdeFileFilter ); if( filter < 1 ) { filter = 1; } } // CTL3D no longer requires this #if !defined( __NT__ ) flags |= OFN_ENABLEHOOK; #endif /* initialize the OPENFILENAME struct */ memset( &wdeofn, 0, sizeof( OPENFILENAME ) ); /* fill in non-variant fields of OPENFILENAME struct */ wdeofn.lStructSize = sizeof( OPENFILENAME ); wdeofn.hwndOwner = owner_window; wdeofn.hInstance = app_inst; wdeofn.lpstrFilter = gf->filter; wdeofn.lpstrCustomFilter = NULL; wdeofn.nMaxCustFilter = 0; wdeofn.nFilterIndex = filter; wdeofn.lpstrFile = wde_file_name; wdeofn.nMaxFile = MAXFILENAME; wdeofn.lpstrFileTitle = wdefntitle; wdeofn.nMaxFileTitle = MAXFILENAME; wdeofn.lpstrInitialDir = wde_initial_dir; wdeofn.lpstrTitle = wdefntitle; wdeofn.Flags = flags; #if !defined( __NT__ ) wdeofn.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance( (FARPROC)WdeOpenHookProc, app_inst ); #endif #if 0 wdeofn.nFileOffset = 0L; wdeofn.nFileExtension = 0L; wdeofn.lpstrDefExt = NULL; wdeofn.lCustData = NULL; wdeofn.lpfnHook = NULL; wdeofn.lpTemplateName = NULL; #endif if( action == WDEOPENFILE ) { ret = GetOpenFileName( (LPOPENFILENAME)&wdeofn ); } else if( action == WDESAVEFILE ) { ret = GetSaveFileName( (LPOPENFILENAME)&wdeofn ); } else { return( NULL ); } #ifndef __NT__ if( wdeofn.lpfnHook != NULL ) { FreeProcInstance( (FARPROC)wdeofn.lpfnHook ); } #endif gf->fn_offset = wdeofn.nFileOffset; gf->ext_offset = wdeofn.nFileExtension; /* show the dialog box */ if( !ret ) { error = CommDlgExtendedError(); if( error ) { WdeDisplayErrorMsg( WDE_ERRORSELECTINGFILE ); } return( NULL ); } else { memcpy( wde_initial_dir, wde_file_name, wdeofn.nFileOffset ); if( wde_initial_dir[wdeofn.nFileOffset - 1] == '\\' && wde_initial_dir[wdeofn.nFileOffset - 2] != ':' ) { wde_initial_dir[wdeofn.nFileOffset - 1] = '\0'; } else { wde_initial_dir[wdeofn.nFileOffset] = '\0'; } _splitpath( wde_file_name, NULL, NULL, NULL, fn_ext + 1 ); if( fn_ext[1] != '\0' ) { fn_ext[0] = '*'; WdeSetFileFilter( fn_ext ); } else { char *out_ext; out_ext = WdeFindFileFilterFromIndex( gf->filter, wdeofn.nFilterIndex ); if( out_ext[2] != '*' ) { strcat( wde_file_name, &out_ext[1] ); } } } UpdateWindow( WdeGetMainWindowHandle() ); return( WdeStrDup( wde_file_name ) ); }
void WdeSetFileFilter( char *filter ) { WdeFreeFileFilter(); WdeFileFilter = WdeStrDup( filter ); }
bool WdeSaveResource( WdeResInfo *res_info, bool get_name ) { WdeGetFileStruct gf; char *filter; char *fn; int fn_offset; bool got_name; bool ok; OBJPTR main_obj; fn_offset = 0; got_name = FALSE; ok = (res_info != NULL && res_info->info != NULL); if( ok ) { if( res_info->info->save_name != NULL ) { fn = res_info->info->save_name; } else { res_info->info->save_type = res_info->info->file_type; fn = WdeStrDup( res_info->info->file_name ); got_name = TRUE; } if( get_name || fn == NULL || *fn == '\0' ) { filter = WdeSelectSaveFilter( res_info->info->file_type ); gf.file_name = fn; gf.title = WdeResSaveTitle; gf.filter = filter; fn = WdeGetSaveFileName( &gf ); got_name = TRUE; res_info->info->save_type = WR_DONT_KNOW; } ok = (fn != NULL && *fn != '\0'); } if( ok ) { if( got_name && res_info->info->save_name != NULL ) { WRMemFree( res_info->info->save_name ); } res_info->info->save_name = fn; if( res_info->info->save_type == WR_DONT_KNOW ) { res_info->info->save_type = WdeSelectFileType( fn, res_info->is32bit ); } ok = (res_info->info->save_type != WR_DONT_KNOW); } if( ok ) { if( WdeIsHashTableDirty( res_info->hash_table ) && !WdeIsHashSaveRejectedSet( res_info->hash_table ) ) { if( res_info->sym_name == NULL ) { res_info->sym_name = WdeCreateSymName( fn ); } } } if( ok ) { if( WdeIsHashTableDirty( res_info->hash_table ) ) { if( (main_obj = GetMainObject()) != NULL ) { Forward( main_obj, RESOLVE_HELPSYMBOL, &ok, NULL ); /* JPK */ Forward( main_obj, RESOLVE_SYMBOL, &ok, NULL ); } } WdeCreateDLGInclude( res_info, res_info->sym_name ); ok = WdeSaveResourceToFile( res_info ); if( !ok ) { WdeDisplayErrorMsg( WDE_SAVEFAILED ); } } if( ok ) { if( WdeIsHashTableDirty( res_info->hash_table ) && !WdeIsHashSaveRejectedSet( res_info->hash_table ) ) { WdeWriteSymbols( res_info->hash_table, &res_info->sym_name, get_name ); } } if( ok ) { //fn_offset = WRFindFnOffset( fn ); SendMessage( res_info->res_win, WM_SETTEXT, 0, (LPARAM)(LPVOID)&fn[fn_offset] ); } return( ok ); }
bool WdeOpenResource( char *fn ) { char *name; WdeResInfo *res_info; WdeGetFileStruct gf; bool ok, got_name; WdeSetWaitCursor( TRUE ); res_info = NULL; name = NULL; got_name = FALSE; if( fn != NULL ) { if( WdeFileExists( fn ) ) { name = WdeStrDup( fn ); gf.fn_offset = WRFindFnOffset( name ); } else { return( FALSE ); } } else { gf.file_name = NULL; gf.title = WdeResOpenTitle; gf.filter = WdeResOpenFilter; ok = ((name = WdeGetOpenFileName( &gf )) != NULL); } if( ok ) { got_name = TRUE; ok = ((res_info = WdeLoadResource( name )) != NULL); } if( ok ) { res_info->hash_table = WRInitHashTable(); ok = (res_info->hash_table != NULL); } if( ok ) { if( res_info->info->internal_type != WR_DONT_KNOW ) { res_info->is32bit = WRIs32Bit( res_info->info->internal_type ); } else { res_info->is32bit = WRIs32Bit( res_info->info->file_type ); } ok = WdeAddDlgItems( res_info ); } if( ok ) { WdeFindAndLoadSymbols( res_info ); ok = WdeCreateResourceWindow( res_info, gf.fn_offset, NULL ); } if( ok ) { if( WdeResInfoHasDialogs( res_info ) ) { WdeSelectDialog( res_info ); } else { WdeDisplayErrorMsg( WDE_PRJHASNODIALOGS ); } ListAddElt( &WdeResList, (void *)res_info ); WdeSetResModified( res_info, FALSE ); WdeCheckBaseScrollbars( FALSE ); } if( !ok ) { if( res_info != NULL ) { WdeFreeResInfo( res_info ); res_info = NULL; } if( got_name ) { WdeDisplayErrorMsg( WDE_RESOURCESNOTLOADED ); } } if( name != NULL ) { WRMemFree( name ); } WdeSetWaitCursor( FALSE ); return( ok ); }
bool WdeSaveObjectAs( WdeResInfo *rinfo, WdeDialogBoxInfo *dbi, char **file_name, WResID *name, void *rdata, uint_32 size, WResLangType *lang, bool get_name ) { char *fname; WRFileType ftype; WdeGetFileStruct gf; WRSaveIntoData idata; WdeResDlgItem ditem; bool is_rc; bool ok; fname = NULL; idata.type = NULL; ok = (rinfo != NULL && dbi != NULL && file_name != NULL && name != NULL && rdata != NULL); if( ok ) { if( get_name || *file_name == NULL ) { gf.file_name = *file_name; gf.title = WdeDlgSaveTitle; if( get_name ) { gf.title = WdeDlgSaveAsTitle; } gf.filter = WdeResSaveFilter; fname = WdeGetSaveFileName( &gf ); } else { fname = WdeStrDup( *file_name ); } ok = (fname != NULL && *fname != '\0'); } if( ok ) { ftype = WdeSelectFileType( fname, rinfo->is32bit ); ok = (ftype != WR_DONT_KNOW); } if( ok ) { is_rc = WdeIsFileAnRCFile( fname ); ok = ((idata.type = WResIDFromNum( RESOURCE2INT( RT_DIALOG ) )) != NULL); } if( ok ) { memset( &ditem, 0, sizeof( WdeResDlgItem ) ); ditem.dialog_info = dbi; ditem.dialog_name = name; if( is_rc ) { ok = WdeSaveObjectToRC( fname, rinfo, &ditem, FALSE ); } } // if we are saving a .RES file then auto create a dlg script if( ok ) { if( ftype == WR_WIN16M_RES || ftype == WR_WIN16W_RES || ftype == WR_WINNTM_RES || ftype == WR_WINNTW_RES ) { char dlgName[_MAX_PATH]; if( WdeCreateDLGName( fname, dlgName ) ) { ok = WdeSaveObjectToRC( dlgName, rinfo, &ditem, FALSE ); } } } if( ok ) { idata.next = NULL; idata.name = name; idata.data = rdata; idata.lang = *lang; idata.size = size; idata.MemFlags = dbi->MemoryFlags; ok = WRSaveObjectAs( fname, ftype, &idata ); } if( idata.type != NULL ) { WResIDFree( idata.type ); } if( ok ) { if( fname != NULL ) { if( *file_name != NULL ) { WRMemFree( *file_name ); } *file_name = fname; } } else { if( fname != NULL ) { WRMemFree( fname ); } } return( ok ); }