📄 drawproc.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 "imgedit.h"
#include <string.h>
#include "iemem.h"
#include "drawproc.h"
static short toolType = 0;
static short cursorIndex = 0;
static HCURSOR hCursor[ NUMBER_OF_CURSORS ];
/*
* lastChanceSave - is called when the user quits and the current image
* is not yet saved. Returns FALSE if CANCEL
* is selected, otherwise, it returns TRUE.
*/
static BOOL lastChanceSave( HWND hwnd )
{
int retcode;
int how;
HMENU hmenu;
img_node *node;
img_node *icon;
char *title;
char *text;
char *msg_text;
char filename[ _MAX_PATH ];
if (!DoImagesExist()) return(TRUE);
node = SelectImage(hwnd);
if (!node) return(TRUE);
icon = GetImageNode( hwnd );
while (icon) {
if (icon->issaved) {
return(TRUE);
}
icon = icon->nexticon;
}
if( strnicmp( node->fname, IEImageUntitled, strlen( IEImageUntitled ) ) != 0 ) {
GetFnameFromPath( node->fname, filename );
how = SB_SAVE;
} else {
strcpy( filename, node->fname );
how = SB_SAVE_AS;
}
retcode = WPI_IDCANCEL;
title = IEAllocRCString( WIE_CLOSETITLE );
text = IEAllocRCString( WIE_QUERYIMAGESAVE );
if( text ) {
msg_text = (char *)MemAlloc( strlen( text ) + strlen( filename ) + 1 );
if( msg_text ) {
sprintf( msg_text, text, filename );
retcode = _wpi_messagebox( HMainWindow, msg_text, title,
MB_YESNOCANCEL | MB_ICONQUESTION );
MemFree( msg_text );
}
IEFreeRCString( text );
}
if( title ) {
IEFreeRCString( title );
}
if (retcode == WPI_IDYES) {
if (!SaveFile( how )) {
PrintHintTextByID( WIE_FILENOTSAVED, NULL );
return (FALSE);
} else {
hmenu = _wpi_getmenu( _wpi_getframe(HMainWindow) );
_wpi_enablemenuitem( hmenu, IMGED_SAVE, FALSE, FALSE );
SetIsSaved( hwnd, TRUE );
}
} else if (retcode == WPI_IDCANCEL) {
return (FALSE);
}
return (TRUE);
} /* lastChanceSave */
/*
* setTheCursor - sets the cursor to be appropriate for the given window.
*/
static void setTheCursor( int cursor_index, HWND hwnd )
{
#ifndef __OS2_PM__
img_node *node;
if (hwnd) {
SET_CLASSCURSOR( hwnd, hCursor[cursorIndex] );
return;
}
cursorIndex = cursor_index;
node = GetHeadNode();
if (!node) return;
while (node) {
SET_CLASSCURSOR( node->hwnd, hCursor[cursorIndex] );
node = node->next;
}
#else
hwnd = hwnd;
cursorIndex = cursor_index;
#endif
} /* setTheCursor */
/*
* DrawAreaWinProc - Windows procedure for the drawing area window. This
* window is an mdi window.
*/
MRESULT CALLBACK DrawAreaWinProc( HWND hwnd, WPI_MSG msg,
WPI_PARAM1 wparam,
WPI_PARAM2 lparam )
{
static WPI_POINT start_pt = {-1, -1};
static WPI_POINT end_pt = {-1, -1};
static WPI_POINT prev_pt = {-1, -1};
static WPI_POINT new_pt = {-1, -1};
static WPI_POINT pt1;
static BOOL flbuttondown = FALSE;
static BOOL frbuttondown = FALSE;
static BOOL fdraw_shape = FALSE;
static BOOL firsttime;
static BOOL wasicon;
int mousebutton;
WPI_POINT pointsize;
WPI_POINT pt2;
#ifndef __OS2_PM__
CREATESTRUCT *cs;
MDICREATESTRUCT *mdi_cs;
MINMAXINFO *minmax;
#endif
img_node *node;
int i;
switch ( msg ) {
case WM_CREATE:
#ifndef __OS2_PM__
cs = (CREATESTRUCT __FAR *)lparam;
mdi_cs = (MDICREATESTRUCT __FAR *)cs->lpCreateParams;
node = (img_node *)mdi_cs->lParam;
for (i=0; i < node->num_of_images; ++i) {
node[i].hwnd = hwnd;
}
AddImageNode( node );
CreateUndoStack( node );
setTheCursor( -1, hwnd );
wasicon = FALSE;
#endif
firsttime = TRUE;
i = i;
return 0 ;
case WM_MDIACTIVATE:
if ( IMGED_GET_MDI_FACTIVATE(hwnd, wparam, lparam) ) {
if (_wpi_isiconic(hwnd)) {
wasicon = TRUE;
break;
} else {
wasicon = FALSE;
FocusOnImage( hwnd );
}
}
return 0;
#ifndef __OS2_PM__
case WM_GETMINMAXINFO:
node = SelectImage( hwnd );
if( node != NULL ) {
minmax = (MINMAXINFO *)lparam;
minmax->ptMinTrackSize.x = node->width +
2 * _wpi_getsystemmetrics(SM_CXFRAME);
minmax->ptMinTrackSize.y = node->height +
2 * _wpi_getsystemmetrics(SM_CYFRAME) +
_wpi_getsystemmetrics( SM_CYCAPTION ) - 1;
}
break;
#endif
case UM_SHOWVIEWWINDOW:
ShowViewWindows( hwnd );
return 0;
case WM_SIZE:
if ( _imgwpi_issizerestored(wparam) ) {
ResizeChild( lparam, hwnd, firsttime );
firsttime = FALSE;
if (wasicon) {
FocusOnImage( hwnd );
wasicon = FALSE;
}
#ifndef __OS2_PM__
// ifdef'ed out until i find out how to minimize and restore windows
} else if ( _imgwpi_issizeminimized( wparam ) ) {
node = SelectImage( hwnd );
HideViewWindow( hwnd );
DeleteActiveImage();
ClearImageText();
SendMessage(ClientWindow, WM_MDINEXT, (WPARAM)(LPVOID)hwnd, 0L);
wasicon = TRUE;
#endif
}
return 0;
#ifndef __OS2_PM__
case WM_CHAR:
pointsize = GetPointSize( hwnd );
if (LOWORD(wparam) == ESC_CHAR) {
if ( !(lparam & 0x40000000) ) {
switch(toolType) {
case IMGED_PASTE:
fdraw_shape = FALSE;
flbuttondown = FALSE;
frbuttondown = FALSE;
DontPaste( hwnd, &pt1, pointsize );
break;
case IMGED_LINE:
case IMGED_RECTO:
case IMGED_RECTF:
case IMGED_CIRCLEO:
case IMGED_CIRCLEF:
case IMGED_CLIP:
if (!flbuttondown && !frbuttondown) {
break;
}
fdraw_shape = FALSE;
flbuttondown = FALSE;
frbuttondown = FALSE;
if ( toolType == IMGED_LINE ) {
OutlineLine(hwnd, &start_pt, &prev_pt, &new_pt, TRUE);
} else if ( toolType == IMGED_CLIP ) {
OutlineClip(hwnd, &start_pt, &prev_pt, &new_pt, TRUE);
SetRectExists( FALSE );
} else {
OutlineRegion(hwnd, &start_pt, &prev_pt, &new_pt, TRUE);
}
break;
default:
break;
}
}
}
return 0;
#endif
case WM_MOUSEMOVE:
pointsize = GetPointSize( hwnd );
#ifdef __OS2_PM__
WinSetPointer( HWND_DESKTOP, hCursor[cursorIndex] );
#endif
IMGED_MAKEPOINT( wparam, lparam, new_pt );
switch(toolType) {
case IMGED_SNAP:
#ifndef __OS2_PM__
OutlineSnap();
#endif
break;
case IMGED_PASTE:
pt1.x = new_pt.x / pointsize.x;
pt1.y = new_pt.y / pointsize.y;
pt2.x = prev_pt.x / pointsize.x;
pt2.y = prev_pt.y / pointsize.y;
if (( pt1.x != pt2.x) || (pt1.y != pt2.y)) {
DragClipBitmap( hwnd, &pt1, pointsize );
}
SetPosInStatus(&new_pt, &pointsize, hwnd);
break;
case IMGED_FREEHAND:
case IMGED_BRUSH:
if (flbuttondown) {
Paint(hwnd, &prev_pt, &new_pt, LMOUSEBUTTON);
} else if (frbuttondown) {
Paint(hwnd, &prev_pt, &new_pt, RMOUSEBUTTON);
}
SetPosInStatus(&new_pt, &pointsize, hwnd);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -