📄 ieopen.c
字号:
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include <windows.h>
#include <commdlg.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <dos.h>
#include <stdlib.h>
#include <cderr.h>
#include "imgedit.h"
#include "colours.h"
#include "iebmpdat.h"
#include "wrdll.h"
#include "wrbitmap.h"
#include "wricon.h"
#include "wrselimg.h"
#include "iemem.h"
#ifdef __NT__
#pragma library("shell32")
#endif
static signed short imgType = BITMAP_IMG;
static char initialDir[ _MAX_PATH+_MAX_DIR ];
extern BOOL OpenNewFiles;
void SetupMenuAfterOpen( void )
{
HMENU hmenu;
hmenu = GetMenu( HMainWindow );
if( !ImgedIsDDE ) {
EnableMenuItem( hmenu, IMGED_REST, MF_ENABLED );
EnableMenuItem( hmenu, IMGED_SAVE, MF_GRAYED );
}
EnableMenuItem( hmenu, IMGED_CLEAR, MF_ENABLED );
EnableMenuItem( hmenu, IMGED_SAVE_AS, MF_ENABLED );
EnableMenuItem( hmenu, IMGED_LINE, MF_ENABLED );
EnableMenuItem( hmenu, IMGED_RECTO, MF_ENABLED );
EnableMenuItem( hmenu, IMGED_RECTF, MF_ENABLED );
EnableMenuItem( hmenu, IMGED_CIRCLEO, MF_ENABLED );
EnableMenuItem( hmenu, IMGED_CIRCLEF, MF_ENABLED );
EnableMenuItem( hmenu, IMGED_FREEHAND, MF_ENABLED );
EnableMenuItem( hmenu, IMGED_FILL, MF_ENABLED );
EnableMenuItem( hmenu, IMGED_BRUSH, MF_ENABLED );
EnableMenuItem( hmenu, IMGED_CLIP, MF_ENABLED );
SetFocus( HMainWindow );
} /* SetupMenuAfterOpen */
static BOOL DoReadInBitmapFile( HBITMAP hbitmap, bitmap_info *bmi,
char *fullname, WRInfo *info,
WResLangNode *lnode )
{
HBITMAP oldbmp1;
HBITMAP oldbmp2;
img_node node;
char filename[ _MAX_FNAME+_MAX_EXT ];
BITMAPINFOHEADER *h;
HDC hdc;
HDC srcdc;
HDC destdc;
GetFnameFromPath( fullname, filename );
if (hbitmap != NULL) {
h = &(bmi->bm_info->bmiHeader);
if ( (h->biWidth > MAX_DIM) || (h->biHeight > MAX_DIM) ) {
WImgEditError( WIE_ERR_BITMAP_TOO_BIG, filename );
MemFree( bmi->bm_info );
DeleteObject( hbitmap );
return( FALSE );
}
/* Should not be an error...
else if (h->biBitCount > 8) {
WImgEditError( WIE_ERR_TOO_MANY_COLOURS, filename );
MemFree( bmi->bm_info );
DeleteObject( hbitmap );
return( FALSE );
}
*/
node.imgtype = BITMAP_IMG;
node.width = bmi->bm_info->bmiHeader.biWidth;
node.height = bmi->bm_info->bmiHeader.biHeight;
node.bitcount = bmi->bm_info->bmiHeader.biBitCount;
node.hotspot.x = 0;
node.hotspot.y = 0;
node.num_of_images = 1;
node.nexticon = NULL;
node.issaved = TRUE;
if (node.bitcount == 1) {
hdc = GetDC( NULL );
srcdc = CreateCompatibleDC( hdc );
destdc = CreateCompatibleDC( hdc );
ReleaseDC( NULL, hdc );
node.hxorbitmap = CreateCompatibleBitmap( destdc, node.width, node.height );
oldbmp1 = SelectObject( srcdc, hbitmap );
oldbmp2 = SelectObject( destdc, node.hxorbitmap );
BitBlt( destdc, 0, 0, node.width, node.height, srcdc, 0, 0, SRCCOPY );
SelectObject( srcdc, oldbmp1 );
SelectObject( destdc, oldbmp2 );
DeleteDC( srcdc );
DeleteDC( destdc );
DeleteObject( hbitmap );
} else {
node.hxorbitmap = hbitmap;
}
strcpy( node.fname, fullname );
PrintHintTextByID( WIE_OPENEDTEXT, filename );
node.wrinfo = info;
node.lnode = lnode;
MakeBitmap( &node, FALSE );
CreateNewDrawPad( &node );
MemFree( bmi->bm_info );
return( TRUE );
}
return( FALSE );
} /* DoReadInBitmapFile */
/*
* readInBitmapFile - reads in the bitmap file, initializes the draw area and
* the view window.
*/
static BOOL readInBitmapFile( char *fullname )
{
bitmap_info bmi;
HBITMAP hbitmap;
HCURSOR prevcursor;
prevcursor = SetCursor( LoadCursor(NULL, IDC_WAIT) );
hbitmap = ReadBitmapFile( HMainWindow, fullname, &bmi );
SetCursor( prevcursor );
if( hbitmap == (HBITMAP)NULL ) {
if( bmi.bm_info != NULL &&
bmi.bm_info->bmiHeader.biBitCount > 32 ) /* Was 8 */ {
WImgEditError( WIE_ERR_TOO_MANY_COLOURS, fullname );
} else {
WImgEditError( WIE_ERR_BAD_BITMAP_FILE, fullname );
}
if( bmi.bm_info != NULL ) {
MemFree( bmi.bm_info );
}
return( FALSE );
}
return( DoReadInBitmapFile( hbitmap, &bmi, fullname, NULL, NULL ) );
} /* readInBitmapFile */
BOOL readBitmapFromData( void *data, char *fullname, WRInfo *info,
WResLangNode *lnode )
{
bitmap_info bmi;
HBITMAP hbitmap;
HCURSOR prevcursor;
BOOL ret;
prevcursor = SetCursor( LoadCursor(NULL, IDC_WAIT) );
hbitmap = BitmapFromData( data, &bmi );
SetCursor( prevcursor );
if( hbitmap == (HBITMAP)NULL ) {
WImgEditError( WIE_ERR_BAD_BITMAP_DATA, fullname );
return( FALSE );
}
ret = DoReadInBitmapFile( hbitmap, &bmi, fullname, info, lnode );
if( ret ) {
SetupMenuAfterOpen();
}
return( ret );
} /* readBitmapFromData */
void WriteIconLoadedText( char *filename, int num )
{
char *text;
char msg[ _MAX_PATH ];
text = IEAllocRCString( WIE_ICONOPENEDTEXT );
if( text ) {
sprintf( msg, text, filename, num );
SetHintText( msg );
IEFreeRCString( text );
}
}
/*
* readInIconFile - Read the icon file and set up structures.
*/
static BOOL readInIconFile( char *fname )
{
FILE *fp;
an_img_file *iconfile;
img_node *node;
int num_of_images;
HDC hdc;
int i;
an_img *icon;
char filename[ _MAX_FNAME+_MAX_EXT ];
fp = fopen( fname, "rb" );
if (!fp) {
WImgEditError( WIE_ERR_FILE_NOT_OPENED, fname );
return( FALSE );
}
GetFnameFromPath( fname, filename );
#ifdef JAMIE
{
char msg[80];
sprintf(msg, "Jamie: IconHeader size = %d", sizeof(an_img_file));
MessageBox(HMainWindow, msg, "FYI", MB_OK);
}
#endif
iconfile = ImageOpen( fp );
if (!iconfile) {
fclose( fp );
WImgEditError( WIE_ERR_BAD_ICON_FILE, filename );
return( FALSE );
}
num_of_images = iconfile->count;
/* See biBitCount test below...
for (i=0; i < num_of_images; ++i) {
if (iconfile->resources[i].colour_count != 2 &&
iconfile->resources[i].colour_count != 8 &&
iconfile->resources[i].colour_count != 16 &&
iconfile->resources[i].colour_count != 0) {
WImgEditError( WIE_ERR_BAD_ICON_CLR, filename );
ImageClose( iconfile );
fclose( fp );
return(FALSE);
}
}
*/
node = MemAlloc( sizeof(img_node) * num_of_images );
hdc = GetDC( NULL );
for (i=0; i < num_of_images; ++i) {
icon = ImgResourceToImg( fp, iconfile, i );
if (icon->bm->bmiHeader.biBitCount != 4 &&
icon->bm->bmiHeader.biBitCount != 1 &&
icon->bm->bmiHeader.biBitCount != 8) {
WImgEditError( WIE_ERR_BAD_ICON_CLR, filename );
ReleaseDC( NULL, hdc );
ImageFini( icon );
ImageClose( iconfile );
fclose( fp );
MemFree( node );
return(FALSE);
}
node[i].imgtype = ICON_IMG;
node[i].bitcount = icon->bm->bmiHeader.biBitCount;
node[i].width = icon->bm->bmiHeader.biWidth;
node[i].height = icon->bm->bmiHeader.biHeight;
node[i].hotspot.x = 0;
node[i].hotspot.y = 0;
node[i].handbitmap = ImgToAndBitmap( hdc, icon );
node[i].hxorbitmap = ImgToXorBitmap( hdc, icon );
node[i].num_of_images = num_of_images;
node[i].viewhwnd = NULL;
node[i].wrinfo = NULL;
node[i].lnode = NULL;
if (i > 0) {
node[i-1].nexticon = &(node[i]);
}
node[i].issaved = TRUE;
node[i].next = NULL;
strcpy( node[i].fname, strupr( fname ) );
ImageFini( icon );
}
node[i-1].nexticon = NULL;
ReleaseDC( NULL, hdc );
ImageClose( iconfile );
fclose( fp );
WriteIconLoadedText( filename, node->num_of_images );
CreateNewDrawPad( node );
MemFree( node );
return(TRUE);
} /* readInIconFile */
/*
* readIconFromData - Read the icon data and set up structures.
*/
BOOL readIconFromData( void *data, char *fname, WRInfo *info,
WResLangNode *lnode )
{
unsigned pos;
an_img_file *iconfile;
img_node *node;
int num_of_images;
HDC hdc;
int i;
an_img *icon;
char filename[ _MAX_FNAME+_MAX_EXT ];
pos = 0;
GetFnameFromPath( fname, filename );
iconfile = ImageOpenData( (BYTE *)data, &pos );
if( !iconfile ) {
WImgEditError( WIE_ERR_BAD_ICON_DATA, filename );
return( FALSE );
}
num_of_images = iconfile->count;
/* See biBitCount test below...
for( i=0; i < num_of_images; ++i ) {
if (iconfile->resources[i].colour_count != 2 &&
iconfile->resources[i].colour_count != 8 &&
iconfile->resources[i].colour_count != 16 &&
iconfile->resources[i].colour_count != 0)
{
WImgEditError( WIE_ERR_BAD_ICON_CLR, filename );
ImageClose( iconfile );
return(FALSE);
}
}
*/
node = MemAlloc( sizeof(img_node) * num_of_images );
hdc = GetDC( NULL );
for( i=0; i < num_of_images; ++i ) {
icon = ImgResourceToImgData( (BYTE *)data, &pos, iconfile, i );
if( ( icon->bm->bmiHeader.biBitCount != 4 ) &&
( icon->bm->bmiHeader.biBitCount != 1 ) &&
( icon->bm->bmiHeader.biBitCount != 8 ) ) {
WImgEditError( WIE_ERR_BAD_ICON_CLR, filename );
ReleaseDC( NULL, hdc );
ImageFini( icon );
ImageClose( iconfile );
MemFree( node );
return(FALSE);
}
node[i].imgtype = ICON_IMG;
node[i].bitcount = icon->bm->bmiHeader.biBitCount;
node[i].width = icon->bm->bmiHeader.biWidth;
node[i].height = icon->bm->bmiHeader.biHeight;
node[i].hotspot.x = 0;
node[i].hotspot.y = 0;
node[i].handbitmap = ImgToAndBitmap( hdc, icon );
node[i].hxorbitmap = ImgToXorBitmap( hdc, icon );
node[i].num_of_images = num_of_images;
node[i].viewhwnd = NULL;
if (i > 0) {
node[i-1].nexticon = &(node[i]);
}
node[i].wrinfo = NULL;
node[i].lnode = NULL;
if( i == 0 ) {
node[i].wrinfo = info;
node[i].lnode = lnode;
}
node[i].issaved = TRUE;
node[i].next = NULL;
strcpy( node[i].fname, strupr( fname ) );
ImageFini( icon );
}
node[i-1].nexticon = NULL;
ReleaseDC( NULL, hdc );
ImageClose( iconfile );
WriteIconLoadedText( filename, node->num_of_images );
CreateNewDrawPad( node );
MemFree( node );
SetupMenuAfterOpen();
return(TRUE);
} /* readIconFromData */
BOOL DoReadCursor( char *fname, an_img_file *cursorfile, an_img *cursor,
WRInfo *info, WResLangNode *lnode )
{
img_node node;
HDC hdc;
char filename[ _MAX_FNAME+_MAX_EXT ];
if( !cursorfile || !cursor ) {
return( FALSE );
}
GetFnameFromPath( fname, filename );
node.imgtype = CURSOR_IMG;
node.width = cursor->bm->bmiHeader.biWidth;
node.height = cursor->bm->bmiHeader.biHeight;
if( node.height == 0 ) {
node.height = node.width;
}
node.bitcount = cursor->bm->bmiHeader.biBitCount;
node.hotspot.x = cursorfile->resources->xhotspot;
node.hotspot.y = cursorfile->resources->yhotspot;
node.issaved = TRUE;
node.num_of_images = 1;
node.next = NULL;
node.nexticon = NULL;
node.wrinfo = info;
node.lnode = lnode;
hdc = GetDC( NULL );
node.handbitmap = ImgToAndBitmap( hdc, cursor );
node.hxorbitmap = ImgToXorBitmap( hdc, cursor );
ReleaseDC( NULL, hdc );
strcpy( node.fname, strupr( fname ) );
ImageFini( cursor );
ImageClose( cursorfile );
PrintHintTextByID( WIE_OPENEDTEXT, filename );
MakeIcon( &node, FALSE ); // also makes cursors
CreateNewDrawPad( &node );
return(TRUE);
} /* DoReadCursor */
/*
* readInCursorFile - Read the cursor file and set up structures.
*/
static BOOL readInCursorFile( char *fname )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -