📄 wreclip.c
字号:
}
ok = ( cname != NULL );
}
if( ok ) {
WREGetCurrentResource( &curr );
if( curr.info == NULL ) {
curr.info = WRECreateNewResource( NULL );
ok = ( curr.info != NULL );
}
}
if( ok ) {
ok = WREHandleClipDataNames( curr.info, ctype, &cname, &replace );
}
if( ok ) {
if( curr.info != NULL ) {
if( curr.info->info->dir ) {
new_type =
( WREFindTypeNodeFromWResID( curr.info->info->dir, ctype )
== NULL );
}
}
ok = WRENewResource( &curr, ctype, cname, DEF_MEMFLAGS, 0,
dsize, &lang, &dup, (uint_16)RT_BITMAP,
new_type ) && !dup;
}
if( ok ) {
curr.lang->data = data;
WRESetResModified( curr.info, TRUE );
}
if( cname != NULL ) {
WREMemFree( cname );
}
if( ctype != NULL ) {
WREMemFree( ctype );
}
return( ok );
}
static Bool WREGetAndPasteDIB( WREClipFormat *fmt )
{
void *data;
uint_32 dsize;
Bool ok;
data = NULL;
ok = ( fmt != NULL );
if( ok ) {
ok = WREGetClipData( fmt, &data, &dsize );
}
if( ok ) {
ok = WREGetAndPasteBitmap( fmt, data, dsize );
}
if( !ok ) {
if( data != NULL ) {
WREMemFree( data );
}
}
return( ok );
}
static Bool WREGetAndPasteHBITMAP( WREClipFormat *fmt )
{
HBITMAP hbitmap;
void *data;
uint_32 dsize;
Bool ok;
data = NULL;
ok = ( fmt != NULL );
if( ok ) {
hbitmap = (HBITMAP) GetClipboardData( fmt->fmt );
ok = ( hbitmap != (HBITMAP)NULL );
}
if( ok ) {
ok = WRWriteBitmapToData( hbitmap, (BYTE **)&data, &dsize );
}
if( ok ) {
ok = WRStripBitmapFileHeader( (BYTE **)&data, &dsize );
}
if( ok ) {
ok = WREGetAndPasteBitmap( fmt, data, dsize );
}
if( !ok ) {
if( data != NULL ) {
WREMemFree( data );
}
}
return( ok );
}
void WREFiniClipboard( void )
{
if( WPrivateFormat != (HBITMAP)NULL ) {
DeleteObject( WPrivateFormat );
}
WRForgetBitmapName();
}
Bool WRERegisterClipFormats( HINSTANCE inst )
{
Bool ok;
int i;
WPrivateFormat = LoadBitmap( inst, "PrivateFmt" );
ok = ( WPrivateFormat != (HBITMAP)NULL );
for( i=0; ok && WREClipFormats[i].fmt_name; i++ ) {
WREClipFormats[i].fmt =
RegisterClipboardFormat( WREClipFormats[i].fmt_name );
ok = ( WREClipFormats[i].fmt != 0 );
}
return( ok );
}
void WRESetCopyMenuItem( HWND main )
{
int enable;
WRECurrentResInfo curr;
HMENU hmenu;
hmenu = GetMenu( main );
WREGetCurrentResource( &curr );
enable = MF_GRAYED;
if( curr.info ) {
if( ( curr.info->current_type != 0 ) &&
( curr.info->current_type != (uint_16)RT_STRING ) ) {
enable = MF_ENABLED;
}
}
EnableMenuItem( hmenu, IDM_CUT, enable );
EnableMenuItem( hmenu, IDM_COPY, enable );
}
void WRESetPasteMenuItem( HWND main )
{
HMENU hmenu;
int enable;
int i;
hmenu = GetMenu( main );
enable = MF_GRAYED;
if( OpenClipboard( main ) ) {
for( i=0; WREClipFormats[i].type; i++ ) {
if( IsClipboardFormatAvailable( WREClipFormats[i].fmt ) ) {
enable = MF_ENABLED;
break;
}
}
CloseClipboard();
}
EnableMenuItem( hmenu, IDM_PASTE, enable );
}
WREClipData *WRECreateClipData( WRECurrentResInfo *curr )
{
WREClipData *cdata;
uint_32 cdata_size;
void *rdata;
uint_32 rdata_size;
void *name;
uint_32 name_size;
uint_16 type;
Bool ok;
cdata = NULL;
rdata = NULL;
name = NULL;
ok = ( curr && curr->type && curr->res && curr->lang );
if( ok ) {
type = 0;
if( !curr->type->Info.TypeName.IsName ) {
type = curr->type->Info.TypeName.ID.Num;
}
ok = ( type != 0 );
}
if( ok ) {
ok = WRWResID2Mem( &curr->res->Info.ResName, &name, &name_size,
curr->info->is32bit );
}
if( ok ) {
if( type == (long)RT_GROUP_ICON ) {
ok = WRECreateIconDataFromGroup( curr, &rdata, &rdata_size );
} else if( type == (long)RT_GROUP_CURSOR ) {
ok = WRECreateCursorDataFromGroup( curr, &rdata, &rdata_size );
} else {
rdata = WREGetCurrentResData( curr );
rdata_size = curr->lang->Info.Length;
ok = ( rdata && rdata_size );
}
}
if( ok ) {
cdata_size = sizeof(WREClipData) + name_size + rdata_size - 1;
cdata = (WREClipData *) WREMemAlloc( cdata_size );
ok = ( cdata != NULL );
}
if( ok ) {
cdata->clip_size = cdata_size;
cdata->data_size = rdata_size;
cdata->data_offset = cdata_size - rdata_size;
cdata->type = type;
cdata->memflags = curr->lang->Info.MemoryFlags;
cdata->is32bit = curr->info->is32bit;
memcpy( &cdata->name[0], name, name_size );
memcpy( &cdata->name[name_size], rdata, rdata_size );
} else {
if( cdata != NULL ) {
WREMemFree( cdata );
cdata = NULL;
}
}
if( rdata != NULL ) {
WREMemFree( rdata );
}
if( name != NULL ) {
WREMemFree( name );
}
return( cdata );
}
Bool WREClipBitmap( WRECurrentResInfo *curr, HWND main )
{
HBITMAP hbitmap;
BYTE *data;
uint_32 dsize;
Bool ok;
data = NULL;
hbitmap = (HBITMAP)NULL;
ok = ( curr && curr->type && curr->res && curr->lang );
if( ok ) {
data = (BYTE *)WREGetCurrentResData( curr );
ok = ( data != NULL );
}
if( ok ) {
dsize = curr->lang->Info.Length;
ok = WREAddBitmapFileHeader( &data, &dsize );
}
if( ok ) {
hbitmap = WRBitmapFromData( data, NULL );
ok = ( hbitmap != (HBITMAP)NULL );
}
if( ok ) {
ok = OpenClipboard( main );
}
if( ok ) {
EmptyClipboard();
SetClipboardData( CF_BITMAP, hbitmap );
CloseClipboard();
hbitmap = (HBITMAP)NULL;
}
if( ok ) {
WRRememberBitmapName( &curr->res->Info.ResName );
}
if( data != NULL ) {
WREMemFree( data );
}
return( ok );
}
Bool WREClipResource( WRECurrentResInfo *curr, HWND main, UINT fmt )
{
WREClipData *cdata;
HGLOBAL hmem;
BYTE *mem;
Bool ok;
HINSTANCE inst;
cdata = NULL;
mem = NULL;
hmem = (HGLOBAL)NULL;
ok = ( curr != NULL && fmt != 0 );
if( ok ) {
cdata = WRECreateClipData( curr );
ok = ( cdata != NULL );
}
if( ok ) {
hmem = GlobalAlloc( GMEM_MOVEABLE, cdata->clip_size );
ok = ( hmem != (HGLOBAL)NULL );
}
if( ok ) {
mem = GlobalLock( hmem );
ok = ( mem != NULL );
}
if( ok ) {
memcpy( mem, cdata, cdata->clip_size );
GlobalUnlock( hmem );
mem = NULL;
ok = OpenClipboard( main );
}
if( ok ) {
EmptyClipboard();
SetClipboardData( fmt, hmem );
SetClipboardData( CF_DSPBITMAP, WPrivateFormat );
inst = WREGetAppInstance();
WPrivateFormat = LoadBitmap( inst, "PrivateFmt" );
CloseClipboard();
hmem = (HGLOBAL)NULL;
ok = ( WPrivateFormat != (HBITMAP)NULL );
}
if( hmem != (HGLOBAL)NULL ) {
GlobalFree( hmem );
}
if( cdata != NULL ) {
WREMemFree( cdata );
}
return( ok );
}
Bool WREClipCurrentResource( HWND main, Bool cut )
{
WRECurrentResInfo curr;
WREClipFormat *fmt;
uint_16 type;
Bool ok;
WREGetCurrentResource( &curr );
ok = ( curr.info && curr.type );
if( ok ) {
type = 0;
if( !curr.type->Info.TypeName.IsName ) {
type = curr.type->Info.TypeName.ID.Num;
}
ok = ( type != 0 );
}
if( ok ) {
fmt = WREFindClipFormatFromType( type );
ok = ( fmt != NULL );
}
if( ok ) {
if( curr.info->current_type == (uint_16)RT_BITMAP ) {
ok = WREClipBitmap( &curr, main );
} else if( ( curr.info->current_type == (uint_16)RT_STRING ) ||
( curr.info->current_type == 0 ) ) {
ok = FALSE;
} else {
ok = WREClipResource( &curr, main, fmt->fmt );
}
}
if( ok ) {
if( cut ) {
ok = WREDeleteCurrResource( TRUE );
}
}
return( ok );
}
Bool WREPasteResource( HWND main )
{
uint_16 type;
WREClipFormat *fmt;
Bool clipbd_open;
Bool ok;
type = 0;
clipbd_open = FALSE;
ok = OpenClipboard( main );
if( ok ) {
clipbd_open = TRUE;
fmt = WREGetClipFormat();
ok = ( fmt != NULL );
}
if( ok ) {
if( fmt->fmt == CF_BITMAP ) {
ok = WREGetAndPasteHBITMAP( fmt );
} else if( fmt->fmt == CF_DIB ) {
ok = WREGetAndPasteDIB( fmt );
} else if( fmt->type == (long)RT_GROUP_ICON ) {
ok = WREGetAndPasteIconOrCursor( fmt );
} else if( fmt->type == (long)RT_GROUP_CURSOR ) {
ok = WREGetAndPasteIconOrCursor( fmt );
} else {
ok = WREGetAndPasteResource( fmt );
}
}
if( clipbd_open ) {
CloseClipboard();
}
return( ok );
}
Bool WREQueryPasteReplace( WResID *name, uint_16 type, Bool *replace )
{
WREPasteData pdata;
HWND dialog_owner;
DLGPROC proc_inst;
HINSTANCE inst;
int ret;
if( !name || !type || !replace ) {
return( FALSE );
}
pdata.ret = 0;
pdata.type = type;
pdata.name = name;
*replace = FALSE;
dialog_owner = WREGetMainWindowHandle();
inst = WREGetAppInstance();
proc_inst = (DLGPROC) MakeProcInstance( (FARPROC)WREResPasteProc, inst );
ret = JDialogBoxParam( inst, "WREPaste", dialog_owner,
proc_inst, (LPARAM) &pdata );
FreeProcInstance( (FARPROC) proc_inst );
if( ( ret == -1 ) || ( ret == IDCANCEL ) ) {
return( FALSE );
}
if( ret == IDM_PASTE_REPLACE ) {
*replace = TRUE;
}
return( TRUE );
}
static void WRESetPasteInfo( HWND hDlg, WREPasteData *pdata )
{
WRETypeName *tn;
char *text;
tn = WREGetTypeNameFromRT( pdata->type );
if( tn ) {
text = WREAllocRCString( tn->name );
WRESetEditWithStr( GetDlgItem( hDlg, IDM_PASTE_TYPE ), text );
if( text ) {
WREFreeRCString( text );
}
}
WRESetEditWithWResID( GetDlgItem( hDlg, IDM_PASTE_NAME ), pdata->name );
}
BOOL WR_EXPORT WREResPasteProc ( HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam )
{
WREPasteData *pdata;
BOOL ret;
ret = FALSE;
switch( message ) {
case WM_INITDIALOG:
pdata = (WREPasteData *)lParam;
SetWindowLong( hDlg, DWL_USER, (LONG)pdata );
WRESetPasteInfo( hDlg, pdata );
ret = TRUE;
break;
case WM_SYSCOLORCHANGE:
WRECtl3dColorChange();
break;
case WM_COMMAND:
switch ( LOWORD(wParam) ) {
case IDM_PASTE_RENAME:
case IDM_PASTE_REPLACE:
pdata = (WREPasteData *)GetWindowLong( hDlg, DWL_USER );
EndDialog( hDlg, LOWORD(wParam) );
ret = TRUE;
break;
case IDCANCEL:
EndDialog( hDlg, IDCANCEL );
ret = TRUE;
break;
}
}
return( ret );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -