/*---------------------------------------------------------------------------- | | child.c | ---------------------------------------------------------------------------*/ #include "precomp.h" #include "demo.h" #include "help.h" #include "resource.h" extern L_INT nChildsNumber; extern HWND hwndRB; typedef struct tagENUMDATA { L_INT nType; L_BOOL bNeedPaint; L_INT nObjectCount; VECTOROBJECT LastObject; RECT Rect; pVECTORGROUP pGroup; } ENUMDATA, *LPENUMDATA; typedef struct _PALETTEINFO { COLORREF *prgbList; L_UINT32 uCount; }PALETTEINFO, *pPALETTEINFO; enum { ENUM_COUNT, ENUM_SELECTALL, ENUM_UNSELECTALL, ENUM_SELECTRECT, ENUM_ADDTOGROUP }; typedef struct tagGROUPSDLGDATA { pVECTORHANDLE pVector; VECTORGROUP Group; } GROUPSDLGDATA, *LPGROUPSDLGDATA; static const L_TCHAR szSaveFileFilter[] = { TEXT("LEAD Vector (VEC)\0") TEXT("*.vec\0") TEXT("AutoCAD DWF\0") TEXT("*.dwf\0") TEXT("AutoCAD DXF\0") TEXT("*.dxf\0") TEXT("Computer Graphics Metafile (CGM)\0") TEXT("*.cgm\0") TEXT("HP-GL2 (PLT)\0") TEXT("*.plt\0") TEXT("Mac PICT (PCT)\0") TEXT("*.pct\0") TEXT("Micrografx (DRW)\0") TEXT("*.drw\0") TEXT("Windows Metafile (WMF)\0") TEXT("*.wmf\0") TEXT("Windows Enhanced Metafile (EMF)\0") TEXT("*.emf\0") TEXT("Gerber File Format (GBR)\0") TEXT("*.gbr\0") TEXT("E S R I (SHP)\0") TEXT("*.shp\0") TEXT("Printer Command Language (PRN)\0") TEXT("*.prn\0") TEXT("Scalable Vector Graphics (SVG)\0") TEXT("*.svg\0") TEXT("Word Perfect Graphics (WPG)\0") TEXT("*.wpg\0") TEXT("Compressed Windows Metafile (WMZ)\0") TEXT("*.wmz\0") }; #define MIN_RESIZE_LIMIT 100 static L_INT nSaveIndex = 0; static COLORREF BackgroundColor = RGB(255,255,255); /* Local functions */ static L_BOOL Child_OnCreate( HWND, LPCREATESTRUCT ); static L_VOID Child_OnMDIActivate( HWND, L_BOOL, HWND, HWND ); static L_VOID Child_OnSetFocus( HWND, HWND ); static L_VOID Child_OnKillFocus( HWND, HWND ); static L_VOID Child_OnPaletteChanged(HWND, HWND ); static L_BOOL Child_OnQueryNewPalette( HWND ); static L_VOID Child_OnSize( HWND, L_UINT, L_INT, L_INT ); static L_BOOL Child_OnEraseBkgnd( HWND, HDC ); static L_VOID Child_OnPaint( HWND ); static L_VOID Child_OnLButtonDown( HWND, L_BOOL, L_INT, L_INT, L_UINT ); static L_VOID Child_OnMouseMove( HWND, L_INT, L_INT, L_UINT ); static L_VOID Child_OnLButtonUp( HWND, L_INT, L_INT, L_UINT ); static L_VOID Child_OnRButtonDown( HWND, L_BOOL, L_INT, L_INT, L_UINT ); static L_VOID Child_OnRButtonUp( HWND, L_INT, L_INT, L_UINT ); static L_VOID Child_OnHScroll( HWND, HWND, L_UINT, L_INT ); static L_VOID Child_OnVScroll( HWND, HWND, L_UINT, L_INT ); static L_VOID Child_OnMouseWheel( HWND, L_UINT, L_INT ); static L_VOID Child_OnCommand( HWND, L_INT, HWND, L_UINT ); static L_VOID Child_OnDestroy( HWND ); static L_INT Child_OnClose( HWND ); static L_VOID OnFileSave( HWND ); static L_VOID OnFileSaveAs( HWND ); static L_VOID OnFilePrint( HWND ); static L_VOID OnFileConvert( L_BOOL ); static L_VOID OnEditUndo( HWND ); static L_VOID OnEditCut( HWND ); static L_VOID OnEditCopy( HWND ); static L_VOID OnEditPaste( HWND, L_INT ); static L_VOID OnEditDelete( HWND ); static L_VOID OnEditSelectAll( HWND ); static L_VOID OnEditUnselectAll( HWND, L_BOOL ); static L_VOID OnViewToolBar( HWND ); static L_VOID OnViewScale( HWND ); static L_VOID OnViewRotate( HWND ); static L_VOID OnViewTranslate( HWND ); static L_VOID OnViewCamera( HWND ); static L_VOID OnViewMode( HWND ); static L_VOID OnViewBackColor( HWND ); static L_VOID OnViewExtent( HWND ); static L_VOID OnLayerEdit( HWND ); static L_VOID OnGroupEdit( HWND ); static L_VOID OnGroupAdd( HWND ); static L_VOID OnObjectExplode( HWND ); static L_VOID OnObjectNew( HWND, L_INT ); static L_VOID OnObjectProperties( HWND ); static L_VOID OnOptionsBindMode( HWND, L_INT ); static L_VOID OnOptionsHitTest( HWND ); static L_VOID OnOptionsRender( HWND ); static L_VOID OnOptionsApplyTransformation( HWND ); static L_VOID OnOptionsInvertColors( HWND ); static L_VOID OnOptionsPalette( HWND ); static L_VOID Child_OnKeyDown( HWND, L_UINT, BOOL, L_INT, L_UINT ); static L_INT EXT_CALLBACK MyEnumObjectsProc( pVECTORHANDLE, const pVECTOROBJECT, L_VOID * ); static L_VOID DisplayTitle( HWND ); static L_VOID UpdateMenuStatus( LPCHILDDATA ); static L_VOID UpdateScrollBars( HWND ); static L_VOID DrawCaptureRect( HWND, LPCHILDDATA ); static L_INT SaveVector( const pVECTORHANDLE, const L_TCHAR *, L_INT ); static L_BOOL CompareObjects( L_CHAR *pObjDesc1, L_CHAR *pObjDesc2, L_INT nType ); static L_INT CompareBrush( pVECTORBRUSH pVectorBrush1, pVECTORBRUSH pVectorBrush2 ); static L_INT ComparePen( pVECTORPEN pVectorPen1, pVECTORPEN pVectorPen2 ); static L_INT ComparePoints( pVECTORPOINT pPoints1, L_INT nPoints1Count, pVECTORPOINT pPoints2, L_INT nPoints2Count ); static L_INT CompareBitmapsData( pBITMAPHANDLE pBitmap1, pBITMAPHANDLE pBitmap2 ); static L_INT PushToUndoBuffer( HWND hWnd ); static L_INT PopFromUndoBuffer( HWND hWnd ); static L_INT CleanUndoData( HWND hWnd ); static L_INT CreateDefaultLayer( pVECTORHANDLE pVector ); static L_BOOL EXT_FUNCTION GroupsDlgProc( HWND, L_UINT, WPARAM, LPARAM ); static L_BOOL EXT_FUNCTION PaletteProc( HWND, L_UINT, WPARAM, LPARAM ); static L_BOOL EXT_FUNCTION ConvertToProc( HWND, L_UINT, WPARAM, LPARAM ); static L_BOOL EXT_FUNCTION ResolveProc( HWND, L_UINT, WPARAM, LPARAM ); L_INT WINAPI myFontMapper( pVECTORHANDLE, LPLOGFONT, L_VOID * ); /*---------------------------------------------------------------------------- | | ChildWIndowProc | ---------------------------------------------------------------------------*/ LRESULT EXT_FUNCTION ChildWindowProc ( HWND hWnd, L_UINT uMessage, WPARAM wParam, LPARAM lParam ) { LPRECT pRect; RECT rcClient; L_INT nRet; switch( uMessage ) { HANDLE_MSG( hWnd, WM_CREATE, Child_OnCreate ); HANDLE_MSG( hWnd, WM_MDIACTIVATE, Child_OnMDIActivate ); HANDLE_MSG( hWnd, WM_SETFOCUS, Child_OnSetFocus ); HANDLE_MSG( hWnd, WM_KILLFOCUS, Child_OnKillFocus ); HANDLE_MSG( hWnd, WM_PALETTECHANGED, Child_OnPaletteChanged ); HANDLE_MSG( hWnd, WM_QUERYNEWPALETTE, Child_OnQueryNewPalette ); HANDLE_MSG( hWnd, WM_SIZE, Child_OnSize ); HANDLE_MSG( hWnd, WM_ERASEBKGND, Child_OnEraseBkgnd ); HANDLE_MSG( hWnd, WM_PAINT, Child_OnPaint ); HANDLE_MSG( hWnd, WM_LBUTTONDOWN, Child_OnLButtonDown ); HANDLE_MSG( hWnd, WM_MOUSEMOVE, Child_OnMouseMove ); HANDLE_MSG( hWnd, WM_LBUTTONUP, Child_OnLButtonUp ); HANDLE_MSG( hWnd, WM_RBUTTONDOWN, Child_OnRButtonDown ); HANDLE_MSG( hWnd, WM_RBUTTONUP, Child_OnRButtonUp ); HANDLE_MSG( hWnd, WM_HSCROLL, Child_OnHScroll ); HANDLE_MSG( hWnd, WM_VSCROLL, Child_OnVScroll ); HANDLE_MSG( hWnd, WM_COMMAND, Child_OnCommand ); HANDLE_MSG( hWnd, WM_DESTROY, Child_OnDestroy ); HANDLE_MSG( hWnd, WM_KEYDOWN, Child_OnKeyDown ); case WM_SIZING: pRect = (LPRECT)lParam; GetClientRect( hWnd, &rcClient ); if( pRect->bottom - pRect->top < MIN_RESIZE_LIMIT ) { switch( wParam ) { case WMSZ_BOTTOM: case WMSZ_BOTTOMLEFT: case WMSZ_BOTTOMRIGHT: pRect->bottom = pRect->top + MIN_RESIZE_LIMIT; return TRUE; case WMSZ_TOP: case WMSZ_TOPLEFT: case WMSZ_TOPRIGHT: pRect->top = pRect->bottom - MIN_RESIZE_LIMIT; return TRUE; } } break; case WM_MOUSEWHEEL: Child_OnMouseWheel( hWnd, wParam, lParam ); return 0; case WM_CLOSE: nRet = Child_OnClose( hWnd ); if ( 1 == nRet ) return nRet; break; } return DefMDIChildProc( hWnd, uMessage, wParam, lParam ); } /*---------------------------------------------------------------------------- | | WM_CREATE | ---------------------------------------------------------------------------*/ static L_BOOL Child_OnCreate ( HWND hWnd, LPCREATESTRUCT pCreateStruct ) { VECTOR_DISPLAY_OPTIONS DispOpt; LPCREATEDATA pCreateData; LPCHILDDATA pData; L_INT nRet; L_UINT uScrollLines; pCreateData = (LPCREATEDATA) CHILDCREATELPARAM( pCreateStruct ); pData = (LPCHILDDATA) GlobalAllocPtr( GHND, sizeof (CHILDDATA) ); if( !pData ) { nRet = ERROR_NO_MEMORY; ShowLeadError( nRet, NULL, NULL ); return FALSE; } pData->bCreatedOK = FALSE; pData->bNewVector = pCreateData->bNewVector; SETCHILDDATA( hWnd, pData ); lstrcpy( pData->szFileName, pCreateData->szFileName ); DisplayTitle( hWnd ); pData->pVector = pCreateData->pVector; pData->nFormat = pCreateData->nFormat; L_VecSetParallelogram( pData->pVector, &pCreateData->Min, &pCreateData->Max ); if( pData->bNewVector ) { L_VecSetOrigin( pData->pVector, NULL ); L_VecSetCamera( pData->pVector, NULL ); L_VecSetBackgroundColor( pData->pVector, RGB( 0xFF, 0xFF, 0xFF ) ); } Hourglass( TRUE ); nRet = L_VecAttachToWindow( hWnd, pData->pVector, pCreateData->nEngine, ( pCreateData->bUseDoubleBuffer ) ? VECTOR_ENGINE_DOUBLEBUFFER : 0L ); Hourglass( FALSE ); if( nRet != SUCCESS ) { ShowLeadError( nRet, NULL, NULL ); return FALSE; } if( L_VecGetEngine( pData->pVector ) == VECTOR_ENGINE_GDI ) { SetScrollRange( hWnd, SB_HORZ, 0, 2, TRUE ); SetScrollPos( hWnd, SB_HORZ, 1, TRUE ); SetScrollRange( hWnd, SB_VERT, 0, 2, TRUE ); SetScrollPos( hWnd, SB_VERT, 1, TRUE ); } else { SetScrollRange( hWnd, SB_HORZ, 0, 0, TRUE ); SetScrollPos( hWnd, SB_HORZ, 0, TRUE ); SetScrollRange( hWnd, SB_VERT, 0, 0, TRUE ); SetScrollPos( hWnd, SB_VERT, 0, TRUE ); } FORWARD_WM_CREATE( hWnd, pCreateStruct, DefMDIChildProc ); pData->bCreatedOK = TRUE; pData->bCapturing = FALSE; pData->rcCapture.left = 0; pData->rcCapture.top = 0; pData->rcCapture.right= 0; pData->rcCapture.bottom = 0; L_VecGetDisplayOptions( pData->pVector, &DispOpt ); DispOpt.nClipMode = VECTOR_CLIPMODE_COPY; L_VecSetDisplayOptions( pData->pVector, &DispOpt ); // Default number of lines to scroll when the mouse wheel is rotated uScrollLines = 3; pData->MouseWheelData.iDeltaPerLine = WHEEL_DELTA / uScrollLines; // Initialize undo settings pData->UndoData.nNumberOfActions = 0; pData->UndoData.szTempFilesNames = NULL; pData->UndoData.bIsDirty = FALSE; // Create Default layer if ( pData->bNewVector ) nRet = CreateDefaultLayer( pData->pVector ); L_VecSetFontMapper( pData->pVector, myFontMapper, TEXT("Arial") ); CHECKMENUITEM( g_hMenuChild, IDM_VIEW_TOOLBAR, g_bIsToolBarVisible ); return nRet; } /*---------------------------------------------------------------------------- | | WM_MDIACTIVATE | ---------------------------------------------------------------------------*/ static L_VOID Child_OnMDIActivate ( HWND hWnd, L_BOOL fActive, HWND hWndActivate, HWND hWndDeactivate ) { LPCHILDDATA pData; UNREFERENCED_PARAMETER( hWndActivate ); UNREFERENCED_PARAMETER( hWndDeactivate ); pData = GETCHILDDATA( hWnd ); if( fActive ) { FORWARD_WM_MDISETMENU( g_hWndClient, TRUE, g_hMenuChild, g_hMenuChildWindow, SendMessage ); SetFocus( hWnd ); } else { FORWARD_WM_MDISETMENU( g_hWndClient, TRUE, g_hMenuFrame, g_hMenuFrameWindow, SendMessage ); } DrawMenuBar( g_hWndFrame ); } /*---------------------------------------------------------------------------- | | WM_SETFOCUS | ---------------------------------------------------------------------------*/ static L_VOID Child_OnSetFocus ( HWND hWnd, HWND hWndOldFocus ) { LPCHILDDATA pData; UNREFERENCED_PARAMETER( hWndOldFocus ); pData = GETCHILDDATA( hWnd ); UpdateMenuStatus( pData ); } /*---------------------------------------------------------------------------- | | WM_KILLFOCUS | ---------------------------------------------------------------------------*/ static L_VOID Child_OnKillFocus ( HWND hWnd, HWND hWndOldFocus ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); UNREFERENCED_PARAMETER( hWndOldFocus ); if( pData->bCapturing ) { DrawCaptureRect( hWnd, pData ); pData->bCapturing = FALSE; ReleaseCapture(); } } L_INT InvertColors( pVECTORHANDLE pVector ) { return L_VecInvertColors( pVector ); } /*---------------------------------------------------------------------------- | | WM_PALETTECHANGED | ---------------------------------------------------------------------------*/ static L_VOID Child_OnPaletteChanged ( HWND hWnd, HWND hWndPaletteChange ) { HDC hDC; HPALETTE hPalette; HPALETTE hOldPalette; LPCHILDDATA pData; pData = GETCHILDDATA( hWnd ); if( hWnd == hWndPaletteChange ) return; hPalette = L_VecGetPalette( pData->pVector ); if( hPalette ) { hDC = GetDC( hWnd ); hOldPalette = SelectPalette( hDC, hPalette, TRUE ); RealizePalette( hDC ); InvalidateRect( hWnd, 0, TRUE ); SelectPalette( hDC, hOldPalette, TRUE ); ReleaseDC( hWnd, hDC ); } } /*---------------------------------------------------------------------------- | | WM_QUERYNEWPALETTE | ---------------------------------------------------------------------------*/ static L_BOOL Child_OnQueryNewPalette ( HWND hWnd ) { HDC hDC; HPALETTE hPalette; HPALETTE hOldPalette; L_INT nNoColors = 0; LPCHILDDATA pData; pData = GETCHILDDATA( hWnd ); hPalette = L_VecGetPalette( pData->pVector ); if( hPalette ) { hDC = GetDC( hWnd ); hOldPalette = SelectPalette( hDC, hPalette, FALSE ); nNoColors = RealizePalette( hDC ); if( nNoColors ) InvalidateRect( hWnd, NULL, FALSE ); SelectPalette( hDC, hOldPalette, TRUE ); ReleaseDC( hWnd, hDC ); } return nNoColors; } /*---------------------------------------------------------------------------- | | WM_SIZE | ---------------------------------------------------------------------------*/ static L_VOID Child_OnSize ( HWND hWnd, L_UINT nState, L_INT nCx, L_INT nCy ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); RECT Rect; GetClientRect( hWnd, &Rect ); L_VecSetViewport( pData->pVector, &Rect ); UpdateScrollBars( hWnd ); SetRect( &Rect, 0, 0, nCx, nCy ); FORWARD_WM_SIZE( hWnd, nState, nCx, nCy, DefMDIChildProc ); } /*---------------------------------------------------------------------------- | | WM_ERASEBKGND | ---------------------------------------------------------------------------*/ static L_BOOL Child_OnEraseBkgnd ( HWND hWnd, HDC hDC ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); HPALETTE hPalette; HPALETTE hOldPalette = NULL; HBRUSH hBrush; RECT Rect; hPalette = L_VecGetPalette( pData->pVector ); if( hPalette ) { hOldPalette = SelectPalette( hDC, hPalette, TRUE ); RealizePalette( hDC ); } GetClientRect( hWnd, &Rect ); hBrush = CreateSolidBrush( L_VecGetBackgroundColor( pData->pVector ) ); FillRect( hDC, &Rect, hBrush ); DeleteObject( hBrush ); if( hPalette ) SelectPalette( hDC, hOldPalette, TRUE ); return TRUE; } /*---------------------------------------------------------------------------- | | WM_PAINT | ---------------------------------------------------------------------------*/ static L_VOID Child_OnPaint ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); PAINTSTRUCT PaintStruct; HDC hDC; HPALETTE hPalette; HPALETTE hOldPalette = NULL; hDC = BeginPaint( hWnd, &PaintStruct ); hPalette = L_VecGetPalette( pData->pVector ); if( hPalette ) { hOldPalette = SelectPalette( hDC, hPalette, TRUE ); RealizePalette( hDC ); } L_VecPaint( hDC, pData->pVector, TRUE ); if( hPalette ) SelectPalette( hDC, hOldPalette, TRUE ); EndPaint( hWnd, &PaintStruct ); } /*---------------------------------------------------------------------------- | | WM_LBUTTONDOWN | ---------------------------------------------------------------------------*/ static L_VOID Child_OnLButtonDown ( HWND hWnd, L_BOOL fDoubleClick, L_INT x, L_INT y, L_UINT uKeyFlags ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); UNREFERENCED_PARAMETER( fDoubleClick ); if( pData->bCapturing ) ReleaseCapture(); if( !g_bViewOnly ) { if( ( uKeyFlags & MK_CONTROL ) != MK_CONTROL ) OnEditUnselectAll( hWnd, TRUE ); pData->bCapturing = TRUE; pData->rcCapture.left = x; pData->rcCapture.top = y; pData->rcCapture.right = x; pData->rcCapture.bottom = y; DrawCaptureRect( hWnd, pData ); SetCapture( hWnd ); } } /*---------------------------------------------------------------------------- | | WM_MOUSEMOVE | ---------------------------------------------------------------------------*/ static L_VOID Child_OnMouseMove ( HWND hWnd, L_INT x, L_INT y, L_UINT uKeyFlags ) { VECTOROBJECT Object; L_BOOL bTemp; L_INT nRet; VECTORTOOLTIPDESC TooltipDesc; LPCHILDDATA pData = GETCHILDDATA( hWnd ); POINT pt; VECTORPOINT Point; UNREFERENCED_PARAMETER( uKeyFlags ); pt.x = x; pt.y = y; L_VecPhysicalToLogical( pData->pVector, &Point, &pt ); StatusBarText( "%Lf, %Lf", Point.x, Point.y ); if( pData->bCapturing ) { DrawCaptureRect( hWnd, pData ); pData->rcCapture.right = x; pData->rcCapture.bottom = y; DrawCaptureRect( hWnd, pData ); } if( TRUE == pData->ChildEx.bValidTooltipObj ) { /* if a tooltip was shown previously remove it*/ L_VecHideObjectTooltip( pData->pVector, &pData->ChildEx.TooltipObj ); pData->ChildEx.bValidTooltipObj = FALSE; InvalidateRect( hWnd, NULL, FALSE ); } nRet = L_VecHitTest( pData->pVector, &pt, &Object ); bTemp = pData->ChildEx.bValidLink; if( SUCCESS == nRet ) { /* we got an object under mouse */ if( 0 < L_VecGetObjectTooltip( pData->pVector, &Object, NULL, 0 ) ) { ZeroMemory( &TooltipDesc, sizeof( TooltipDesc ) ); TooltipDesc.Point.x = x; if ( 30 < y ) TooltipDesc.Point.y = y - 30; else TooltipDesc.Point.y = y + 30; TooltipDesc.Pen.lopnColor = RGB( 0, 0, 0 ); TooltipDesc.Pen.lopnWidth.x = 1; TooltipDesc.Brush.lbColor = RGB( 0xFF, 0xFF, 0xE1 ); //strcpy( TooltipDesc.Font.lfFaceName, "Times New Roman" ); TooltipDesc.Font.lfHeight = 30; nRet = L_VecShowObjectTooltip( pData->pVector, &Object, &TooltipDesc ); InvalidateRect( hWnd, NULL, FALSE ); if( SUCCESS == nRet ) { pData->ChildEx.TooltipObj = Object; pData->ChildEx.bValidTooltipObj = TRUE; pData->ChildEx.TooltipDesc = TooltipDesc; } } if( 0 < L_VecGetHyperlinkCount( pData->pVector, &Object ) ) { bTemp = TRUE; pData->ChildEx.LinkObj = Object; } else { bTemp = FALSE; } } else { bTemp = FALSE; } if( bTemp != pData->ChildEx.bValidLink ) { LinkHand( hWnd, bTemp ); pData->ChildEx.bValidLink = bTemp; } } /*---------------------------------------------------------------------------- | | WM_LBUTTONUP | ---------------------------------------------------------------------------*/ static L_VOID Child_OnLButtonUp ( HWND hWnd, int x, int y, UINT uKeyFlags ) { L_INT nResult; L_UINT32 uCount; LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nTemp; POINT pt; VECTOROBJECT Object; L_INT nRet; ENUMDATA EnumData; UNREFERENCED_PARAMETER( x ); UNREFERENCED_PARAMETER( y ); UNREFERENCED_PARAMETER( uKeyFlags ); if( pData->bCapturing ) { DrawCaptureRect( hWnd, pData ); pData->bCapturing = FALSE; ReleaseCapture(); if( pData->rcCapture.left > pData->rcCapture.right ) { nTemp = pData->rcCapture.left; pData->rcCapture.left = pData->rcCapture.right; pData->rcCapture.right = nTemp; } if( pData->rcCapture.top > pData->rcCapture.bottom ) { nTemp = pData->rcCapture.top; pData->rcCapture.top = pData->rcCapture.bottom; pData->rcCapture.bottom = nTemp; } if( pData->rcCapture.left == pData->rcCapture.right && pData->rcCapture.top == pData->rcCapture.bottom ) { pt.x = pData->rcCapture.left; pt.y = pData->rcCapture.top; nRet = L_VecHitTest( pData->pVector, &pt, &Object ); if( nRet == SUCCESS ) { PushToUndoBuffer( hWnd ); L_VecSelectObject( pData->pVector, &Object, TRUE ); InvalidateRect( hWnd, NULL, FALSE ); UpdateMenuStatus( pData ); } } else { memset( &EnumData, 0, sizeof( ENUMDATA ) ); EnumData.nType = ENUM_SELECTRECT; CopyRect( &EnumData.Rect, &pData->rcCapture ); nRet = L_VecEnumObjects( pData->pVector, MyEnumObjectsProc, &EnumData, 0L ); if( nRet != SUCCESS ) ShowLeadError( nRet, NULL, NULL ); if( EnumData.bNeedPaint ) { PushToUndoBuffer( hWnd ); InvalidateRect( hWnd, NULL, FALSE ); UpdateMenuStatus( pData ); UpdateMenuStatus( pData ); } } } if( TRUE == pData->ChildEx.bValidLink ) { /* we're over a link object */ uCount = L_VecGetHyperlinkCount( pData->pVector, &pData->ChildEx.LinkObj ); switch( uCount ) { case 0: return; case 1: nResult = 0; break; default: /* we need to resolve ambiguity */ nResult = DialogBoxParam( g_hInstance, MAKEINTRESOURCE( IDD_MULTIPLETARGETS ), GetParent( hWnd ), (DLGPROC)ResolveProc, (LPARAM)pData ); if( LB_ERR == nResult ) { return ; } break; } /* nResult has the index of the hyperlink which we should use */ if( SUCCESS != L_VecGotoHyperlink( pData->pVector, &pData->ChildEx.LinkObj, (L_UINT32)nResult ) ) { MessageBoxA( GetParent( hWnd ), "Unable to jump to the link", "Error", MB_OK | MB_ICONERROR ); } } } /*---------------------------------------------------------------------------- | | WM_RBUTTONDOWN | ---------------------------------------------------------------------------*/ static L_VOID Child_OnRButtonDown ( HWND hWnd, L_BOOL fDoubleClick, L_INT x, L_INT y, L_UINT uKeyFlags ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); UNREFERENCED_PARAMETER( fDoubleClick ); UNREFERENCED_PARAMETER( uKeyFlags ); if( pData->bCapturing ) ReleaseCapture(); pData->bCapturing = TRUE; pData->rcCapture.left = x; pData->rcCapture.top = y; pData->rcCapture.right = x; pData->rcCapture.bottom = y; DrawCaptureRect( hWnd, pData ); SetCapture( hWnd ); } /*---------------------------------------------------------------------------- | | WM_RBUTTONUP | ---------------------------------------------------------------------------*/ static L_VOID Child_OnRButtonUp ( HWND hWnd, int x, int y, UINT uKeyFlags ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nTemp; UNREFERENCED_PARAMETER( x ); UNREFERENCED_PARAMETER( y ); UNREFERENCED_PARAMETER( uKeyFlags ); if( pData->bCapturing ) { DrawCaptureRect( hWnd, pData ); pData->bCapturing = FALSE; ReleaseCapture(); if( pData->rcCapture.left > pData->rcCapture.right ) { nTemp = pData->rcCapture.left; pData->rcCapture.left = pData->rcCapture.right; pData->rcCapture.right = nTemp; } if( pData->rcCapture.top > pData->rcCapture.bottom ) { nTemp = pData->rcCapture.top; pData->rcCapture.top = pData->rcCapture.bottom; pData->rcCapture.bottom = nTemp; } if( pData->rcCapture.left != pData->rcCapture.right && pData->rcCapture.top != pData->rcCapture.bottom ) { L_VecZoomRect( pData->pVector, &pData->rcCapture ); UpdateScrollBars( hWnd ); InvalidateRect( hWnd, NULL, TRUE ); } } } /*---------------------------------------------------------------------------- | | WM_HSCROLL | ---------------------------------------------------------------------------*/ static L_VOID Child_OnHScroll ( HWND hWnd, HWND hWndCtl, L_UINT uCode, L_INT nPos ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nMin, nMax; L_INT nOldPos, nNewPos; RECT Rect; L_INT nLine, nPage; POINT ptPan, ptPanOld; UNREFERENCED_PARAMETER( hWndCtl ); if( L_VecGetEngine( pData->pVector ) != VECTOR_ENGINE_GDI ) return; GetScrollRange( hWnd, SB_HORZ, &nMin, &nMax ); nOldPos = GetScrollPos( hWnd, SB_HORZ ); nNewPos = nOldPos; GetClientRect( hWnd, &Rect ); nLine = Rect.right / 10; nPage = Rect.right / 4; switch( uCode ) { case SB_LINELEFT: nNewPos -= nLine; break; case SB_LINERIGHT: nNewPos += nLine; break; case SB_PAGELEFT: nNewPos -= nPage; break; case SB_PAGERIGHT: nNewPos += nPage; break; case SB_LEFT: nNewPos = nMin; break; case SB_RIGHT: nNewPos = nMax; break; case SB_THUMBTRACK: case SB_THUMBPOSITION: nNewPos = nPos; break; default: break; } L_VecGetPan( pData->pVector, &ptPanOld ); ptPan.x = ptPanOld.x + ( nNewPos - nOldPos ); if( ptPan.x != ptPanOld.x ) { SetScrollPos( hWnd, SB_HORZ, nNewPos, TRUE ); ptPan.y = ptPanOld.y; L_VecSetPan( pData->pVector, &ptPan ); InvalidateRect( hWnd, NULL, FALSE ); } } /*---------------------------------------------------------------------------- | | WM_VSCROLL | ---------------------------------------------------------------------------*/ static L_VOID Child_OnVScroll ( HWND hWnd, HWND hWndCtl, L_UINT uCode, L_INT nPos ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nMin, nMax; L_INT nOldPos, nNewPos; RECT Rect; L_INT nLine, nPage; POINT ptPan, ptPanOld; UNREFERENCED_PARAMETER( hWndCtl ); if( L_VecGetEngine( pData->pVector ) != VECTOR_ENGINE_GDI ) return; GetScrollRange( hWnd, SB_VERT, &nMin, &nMax ); nOldPos = GetScrollPos( hWnd, SB_VERT ); nNewPos = nOldPos; GetClientRect( hWnd, &Rect ); nLine = Rect.bottom / 10; nPage = Rect.bottom / 4; switch( uCode ) { case SB_LINEUP: nNewPos -= nLine; break; case SB_LINEDOWN: nNewPos += nLine; break; case SB_PAGEUP: nNewPos -= nPage; break; case SB_PAGEDOWN: nNewPos += nPage; break; case SB_TOP: nNewPos = nMin; break; case SB_BOTTOM: nNewPos = nMax; break; case SB_THUMBTRACK: case SB_THUMBPOSITION: nNewPos = nPos; break; default: break; } L_VecGetPan( pData->pVector, &ptPanOld ); ptPan.y = ptPanOld.y + ( nNewPos - nOldPos ); if( ptPan.y != ptPanOld.y ) { SetScrollPos( hWnd, SB_VERT, nNewPos, TRUE ); ptPan.x = ptPanOld.x; L_VecSetPan( pData->pVector, &ptPan ); InvalidateRect( hWnd, NULL, FALSE ); } } /*---------------------------------------------------------------------------- | | WM_MOUSEWHEEL | ---------------------------------------------------------------------------*/ static L_VOID Child_OnMouseWheel ( HWND hWnd, L_UINT wParam, L_INT lParam ) { L_INT iDeltaPerLine = 0; L_INT iAccumDelta = 0; LPCHILDDATA pData = GETCHILDDATA( hWnd ); UNREFERENCED_PARAMETER( lParam ); iDeltaPerLine = pData->MouseWheelData.iDeltaPerLine; if( 0 == iDeltaPerLine ) return; iAccumDelta += (L_INT16) HIWORD( wParam ); while( iAccumDelta >= iDeltaPerLine ) { SendMessage( hWnd, WM_VSCROLL, SB_LINEUP, 0 ); iAccumDelta -= iDeltaPerLine; } while( iAccumDelta <= -iDeltaPerLine ) { SendMessage( hWnd, WM_VSCROLL, SB_LINEDOWN, 0 ); iAccumDelta += iDeltaPerLine; } return; } /*---------------------------------------------------------------------------- | | WM_COMMAND | ---------------------------------------------------------------------------*/ static L_VOID Child_OnCommand ( HWND hWnd, L_INT nId, HWND hWndCtl, L_UINT uCodeNotify ) { UNREFERENCED_PARAMETER( hWndCtl ); UNREFERENCED_PARAMETER( uCodeNotify ); switch( nId ) { case IDM_FILE_SAVE: OnFileSave( hWnd ); break; case IDM_FILE_SAVEAS: OnFileSaveAs( hWnd ); break; case IDM_FILE_PRINT: OnFilePrint( hWnd ); break; case ID_FILE_CONVERT_EMF: case ID_FILE_CONVERT_WMF: OnFileConvert( ID_FILE_CONVERT_EMF == nId ); break; case IDM_EDIT_UNDO: OnEditUndo( hWnd ); break; case IDM_EDIT_CUT: OnEditCut( hWnd ); break; case IDM_EDIT_COPY: OnEditCopy( hWnd ); break; case IDM_EDIT_PASTE_OBJECTS: case IDM_EDIT_PASTE_LAYERS: OnEditPaste( hWnd, nId ); break; case IDM_EDIT_DELETE: OnEditDelete( hWnd ); break; case IDM_EDIT_SELECTALL: OnEditSelectAll( hWnd ); break; case IDM_EDIT_UNSELECTALL: OnEditUnselectAll( hWnd, TRUE ); break; case IDM_VIEW_TOOLBAR: OnViewToolBar( hWnd ); break; case IDM_VIEW_SCALE: OnViewScale( hWnd ); break; case IDM_VIEW_ROTATE: OnViewRotate( hWnd ); break; case IDM_VIEW_TRANSLATE: OnViewTranslate( hWnd ); break; case IDM_VIEW_CAMERA: OnViewCamera( hWnd ); break; case IDM_VIEW_MODE: OnViewMode( hWnd ); break; case IDM_VIEW_BACKCOLOR: OnViewBackColor( hWnd ); break; case IDM_VIEW_EXTENT: OnViewExtent( hWnd ); break; case IDM_LAYER_EDIT: OnLayerEdit( hWnd ); break; case IDM_GROUP_EDIT: OnGroupEdit( hWnd ); break; case IDM_GROUP_ADD: OnGroupAdd( hWnd ); break; case IDM_OBJECT_EXPLODE: OnObjectExplode( hWnd ); break; case IDM_OBJECT_NEW_VERTEX: case IDM_OBJECT_NEW_LINE: case IDM_OBJECT_NEW_RECTANGLE: case IDM_OBJECT_NEW_POLYLINE: case IDM_OBJECT_NEW_POLYBEZIER: case IDM_OBJECT_NEW_POLYGON: case IDM_OBJECT_NEW_ELLIPSE: case IDM_OBJECT_NEW_CIRCLE: case IDM_OBJECT_NEW_ARC: case IDM_OBJECT_NEW_ELLIPTICALARC: case IDM_OBJECT_NEW_TEXT: case IDM_OBJECT_NEW_PIE: case IDM_OBJECT_NEW_CHORD: case IDM_OBJECT_NEW_POLYDRAW: case IDM_OBJECT_NEW_RASTER: case IDM_OBJECT_NEW_CLONE: case IDM_OBJECT_NEW_SPLINE: case IDM_OBJECT_NEW_HPOLYBEZIER: OnObjectNew( hWnd, nId ); break; case IDM_OBJECT_PROPERTIES: OnObjectProperties( hWnd ); break; case IDM_OPTIONS_BINDMODE_BINDVERTICES: case IDM_OPTIONS_BINDMODE_UNBINDVERTICES: OnOptionsBindMode( hWnd, nId ); break; case IDM_OPTIONS_HITTEST: OnOptionsHitTest( hWnd ); break; case IDM_OPTIONS_RENDER: OnOptionsRender( hWnd ); break; case IDM_OPTIONS_APPLYTRANSFORMATION: OnOptionsApplyTransformation( hWnd ); break; case ID_OPTIONS_INVERTCOLORS: OnOptionsInvertColors( hWnd ); break; case ID_OPTIONS_PALETTE: OnOptionsPalette( hWnd ); break; default: break; } } /*---------------------------------------------------------------------------- | | WM_DESTROY | ---------------------------------------------------------------------------*/ static L_VOID Child_OnDestroy ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); if( pData ) { if( pData->bCreatedOK ) { L_VecFree( pData->pVector ); GlobalFreePtr( pData->pVector ); } GlobalFreePtr( pData ); StatusBarText( NULL ); } } /*---------------------------------------------------------------------------- | | Child_OnClose | ---------------------------------------------------------------------------*/ static L_INT Child_OnClose ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet = 0; L_TCHAR *pszTemp = NULL; L_TCHAR szTitle [L_MAXPATH]; L_TCHAR szMessage[L_MAXPATH]; if ( pData->UndoData.bIsDirty ) { GetWindowText( hWnd, szTitle, sizeof(szTitle)/sizeof(L_TCHAR) ); #ifdef _UNICODE pszTemp = wcsrchr( szTitle, TEXT('\\') ); #else pszTemp = strrchr( szTitle, '\\' ); #endif lstrcpy( szMessage, TEXT("Save changes to \"") ); if ( NULL != pszTemp ) lstrcat( szMessage, pszTemp + 1 ); else lstrcat( szMessage, szTitle ); lstrcat( szMessage, TEXT("\" ? ") ); nRet = MessageBox( hWnd, szMessage, TEXT("Vector"), MB_YESNOCANCEL | MB_ICONEXCLAMATION ); if ( IDYES == nRet ) { OnFileSave( hWnd ); nRet = 0; } else if ( IDNO == nRet ) nRet = 0; else if ( IDCANCEL == nRet ) nRet = 1; } if ( 0 == nRet ) { CleanUndoData( hWnd ); nChildsNumber--; } if ( 0 == nChildsNumber ) { SendMessage( hwndRB, RB_SHOWBAND, 0, (LPARAM) FALSE ); g_bIsToolBarVisible = FALSE; CHECKMENUITEM( g_hMenuChild, IDM_VIEW_TOOLBAR, g_bIsToolBarVisible ); } return nRet; } /*---------------------------------------------------------------------------- | | File/Save | ---------------------------------------------------------------------------*/ static L_VOID OnFileSave ( HWND hWnd ) { OPENFILENAME OpenFileName; L_TCHAR szFileName[ _MAX_PATH ] = TEXT(""); static L_TCHAR szFileTitle[ _MAX_PATH ] = TEXT(""); LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nFormat; L_TCHAR szBuffer[L_MAXPATH]; L_UINT uSize = 0; L_INT nRet; ZeroMemory( &OpenFileName, sizeof( OPENFILENAME ) ); ZeroMemory( szFileName, _MAX_PATH ); lstrcpy( szFileTitle, TEXT("") ); OpenFileName.lStructSize = sizeof( OPENFILENAME ); OpenFileName.hwndOwner = hWnd; OpenFileName.hInstance = NULL; OpenFileName.lpstrFilter = szSaveFileFilter; OpenFileName.lpstrCustomFilter = NULL; OpenFileName.nMaxCustFilter = 0; OpenFileName.nFilterIndex = nSaveIndex; OpenFileName.lpstrFile = szFileName; OpenFileName.nMaxFile = sizeof( szFileName )/sizeof(L_TCHAR); OpenFileName.lpstrFileTitle = szFileName; OpenFileName.nMaxFileTitle = sizeof( szFileName )/sizeof(L_TCHAR); OpenFileName.lpstrInitialDir = NULL; OpenFileName.lpstrTitle = TEXT("Save Vector As"); OpenFileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; OpenFileName.nFileOffset = 0; OpenFileName.nFileExtension = 0; OpenFileName.lpstrDefExt = TEXT(""); OpenFileName.lCustData = 0L; OpenFileName.lpfnHook = NULL; OpenFileName.lpTemplateName = NULL; if ( ! pData->bNewVector ) { lstrcpy( szFileName, pData->szFileName ); nFormat = pData->nFormat; } else { if( !GetSaveFileName( &OpenFileName ) ) return; nSaveIndex = OpenFileName.nFilterIndex; switch( nSaveIndex ) { case 1: nFormat = FILE_VECTOR_DUMP; break; case 2: nFormat = FILE_DWF; break; case 3: nFormat = FILE_DXF; break; case 4: nFormat = FILE_CGM; break; case 5: nFormat = FILE_PLT; break; case 6: nFormat = FILE_PCT; break; case 7: nFormat = FILE_DRW; break; case 8: nFormat = FILE_WMF; break; case 9: nFormat = FILE_EMF; break; case 10: nFormat = FILE_GERBER; break; case 11: nFormat = FILE_SHP; break; case 12: nFormat = FILE_PCL; break; case 13: nFormat = FILE_SVG; break; case 14: nFormat = FILE_VWPG; break; case 15: nFormat = FILE_WMZ; break; default: ShowLeadError( ERROR_FILE_FORMAT, NULL, NULL ); return; } } nRet = SaveVector( pData->pVector, szFileName, nFormat ); if( SUCCESS == nRet ) { pData->bNewVector = FALSE; lstrcpy( pData->szFileName,szFileName ); pData->nFormat = nFormat; } pData->UndoData.bIsDirty = FALSE; if ( ! pData->UndoData.bIsDirty ) { GetWindowText( hWnd, szBuffer, sizeof(szBuffer) ); uSize = lstrlen( szBuffer ); szBuffer[uSize - 1] = '\0'; SetWindowText( hWnd, szBuffer ); } } /*---------------------------------------------------------------------------- | | Child_OnKeyDown | ---------------------------------------------------------------------------*/ static L_VOID Child_OnKeyDown ( HWND hWnd, L_UINT uVk, BOOL fDown, L_INT nRepeat, L_UINT uFlags ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_UINT uNewWidth; L_UINT uNewHeight; L_INT nWidthDiff; L_INT nHeightDiff; L_INT nTemp; L_INT nRet; VECTORPOINT ptMin; VECTORPOINT ptMax; UNREFERENCED_PARAMETER( fDown ); UNREFERENCED_PARAMETER( nRepeat ); UNREFERENCED_PARAMETER( uFlags ); if ( (VK_ADD != uVk) && (VK_SUBTRACT != uVk) ) return; if ( VK_ADD == uVk ) { nTemp = 90; } else { nTemp = 110; } nRet = L_VecGetParallelogram( pData->pVector, &ptMin, &ptMax ); if ( SUCCESS != nRet ) return; uNewWidth = MulDiv( (L_INT)( ptMax.x - ptMin.x ), nTemp, 100 ); uNewHeight = MulDiv( (L_INT)( ptMax.y - ptMin.y ), nTemp, 100 ); nWidthDiff = uNewWidth - (L_INT)( ptMax.x - ptMin.x ); nHeightDiff = uNewHeight - (L_INT)( ptMax.y - ptMin.y ); ptMin.x -= nWidthDiff / 2; ptMin.y -= nHeightDiff / 2; ptMax.x += nWidthDiff / 2; ptMax.y += nHeightDiff / 2; nRet = L_VecSetParallelogram( pData->pVector, &ptMin, &ptMax ); UpdateScrollBars( hWnd ); InvalidateRect( hWnd, NULL, TRUE ); // if ( VK_ADD == uKeyCode ) // { // nTemp = 110; // } // // else // { // nTemp = 90; // } // // if( pData->ZoomData.rcZoomRect.left > pData->ZoomData.rcZoomRect.right ) // { // uTemp = pData->ZoomData.rcZoomRect.left; // pData->ZoomData.rcZoomRect.left = pData->ZoomData.rcZoomRect.right; // pData->ZoomData.rcZoomRect.right = uTemp; // } // // if( pData->ZoomData.rcZoomRect.top > pData->ZoomData.rcZoomRect.bottom ) // { // uTemp = pData->ZoomData.rcZoomRect.top; // pData->ZoomData.rcZoomRect.top = pData->ZoomData.rcZoomRect.bottom; // pData->ZoomData.rcZoomRect.bottom = uTemp; // } // // if( pData->ZoomData.rcZoomRect.left != pData->ZoomData.rcZoomRect.right && // pData->ZoomData.rcZoomRect.top != pData->ZoomData.rcZoomRect.bottom ) // { // uNewHeight = MulDiv( (pData->ZoomData.rcZoomRect.bottom - pData->ZoomData.rcZoomRect.top), nTemp, 100 ); // // uNewWidth = MulDiv( (pData->ZoomData.rcZoomRect.right - pData->ZoomData.rcZoomRect.left), nTemp, 100 ); // // nHeightDiff = uNewHeight - ( pData->ZoomData.rcZoomRect.bottom - pData->ZoomData.rcZoomRect.top ); // // nWidthDiff = uNewWidth - ( pData->ZoomData.rcZoomRect.right - pData->ZoomData.rcZoomRect.left ); // // pData->ZoomData.rcZoomRect.bottom += nHeightDiff / 2; // // pData->ZoomData.rcZoomRect.left -= nWidthDiff / 2; // // pData->ZoomData.rcZoomRect.right += nWidthDiff / 2; // // pData->ZoomData.rcZoomRect.top -= nHeightDiff / 2; // // nRet = L_VecSetViewport( pData->pVector, &pData->ZoomData.rcZoomRect ); // // UpdateScrollBars( hWnd ); // // InvalidateRect( hWnd, NULL, TRUE ); // } } /*---------------------------------------------------------------------------- | | File/SaveAs | ---------------------------------------------------------------------------*/ static L_VOID OnFileSaveAs ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_BOOL bTemp = pData->bNewVector; pData->bNewVector = TRUE; OnFileSave( hWnd ); pData->bNewVector = bTemp; } /*---------------------------------------------------------------------------- | | OnFileConvert | ---------------------------------------------------------------------------*/ static L_VOID OnFileConvert ( L_BOOL bEMF ) { L_INT nRet; HDC hDC; HWND hWndChild; LPCHILDDATA pData; CONVERTDATA ConvertData; hWndChild = FORWARD_WM_MDIGETACTIVE( g_hWndClient, SendMessage ); if( hWndChild ) { pData = GETCHILDDATA( hWndChild ); if( pData && pData->pVector ) { /* Fill initialization data */ hDC = GetDC( NULL ); ConvertData.uDPI = (L_UINT)GetDeviceCaps( hDC, LOGPIXELSX ); ConvertData.szFileName[ 0 ] = 0; ConvertData.Rect = pData->pVector->rcViewport; ConvertData.bEMF = bEMF; ConvertData.hDC = hDC; ConvertData.pData = pData; nRet = DialogBoxParam( g_hInstance, MAKEINTRESOURCE( IDD_CONVERT ), g_hWndClient, (DLGPROC)ConvertToProc, (LPARAM)&ConvertData ); ReleaseDC( NULL, hDC ); } } } /*---------------------------------------------------------------------------- | | File/Print | ---------------------------------------------------------------------------*/ static L_VOID OnFilePrint ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); PRINTDLG PrintDlgStruct; RECT Rect; DOCINFO DocInfo; L_INT nRet; ZeroMemory( &PrintDlgStruct, sizeof( PRINTDLG ) ); PrintDlgStruct.lStructSize = sizeof( PRINTDLG ); PrintDlgStruct.hwndOwner = hWnd; PrintDlgStruct.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION; if( PrintDlg( &PrintDlgStruct ) ) { if( PrintDlgStruct.hDC != NULL ) { Rect.left = GetDeviceCaps( PrintDlgStruct.hDC, PHYSICALOFFSETX ); Rect.top = GetDeviceCaps( PrintDlgStruct.hDC, PHYSICALOFFSETY ); Rect.right = GetDeviceCaps( PrintDlgStruct.hDC, PHYSICALWIDTH ) - Rect.left * 2; Rect.bottom = GetDeviceCaps( PrintDlgStruct.hDC, PHYSICALHEIGHT ) - Rect.top * 2; DocInfo.cbSize = sizeof( DOCINFO ); DocInfo.lpszDocName = pData->szFileName; DocInfo.lpszOutput = NULL; DocInfo.lpszDatatype = NULL; StartDoc( PrintDlgStruct.hDC, &DocInfo ); StartPage( PrintDlgStruct.hDC ); SetMapMode( PrintDlgStruct.hDC, MM_TEXT ); L_VecPaintDC( PrintDlgStruct.hDC, pData->pVector, 1000, 1000, NULL, NULL, &Rect, NULL, 0L ); EndPage( PrintDlgStruct.hDC ); EndDoc( PrintDlgStruct.hDC ); nRet = SUCCESS; DeleteDC( PrintDlgStruct.hDC ); } else nRet = ERROR_NO_MEMORY; if( nRet != SUCCESS ) ShowLeadError( nRet, NULL, NULL ); } } /*---------------------------------------------------------------------------- | | Edit/Undo | ---------------------------------------------------------------------------*/ static L_VOID OnEditUndo ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); RECT Rect; Hourglass( TRUE ); PopFromUndoBuffer( hWnd ); Hourglass( FALSE ); GetClientRect( hWnd, &Rect ); L_VecSetViewport( pData->pVector, &Rect ); UpdateMenuStatus( pData ); UpdateScrollBars( hWnd ); InvalidateRect( hWnd, NULL, TRUE ); } /*---------------------------------------------------------------------------- | | Edit/Cut | ---------------------------------------------------------------------------*/ static L_VOID OnEditCut ( HWND hWnd ) { OnEditCopy( hWnd ); OnEditDelete( hWnd ); } /*---------------------------------------------------------------------------- | | Edit/Copy | ---------------------------------------------------------------------------*/ static L_VOID OnEditCopy ( HWND hWnd ) { L_INT nRet; LPCHILDDATA pData = GETCHILDDATA( hWnd ); Hourglass( TRUE ); nRet = L_VecCopyToClipboard( hWnd, pData->pVector, VECTOR_FLAGS_SELECTED_ONLY ); Hourglass( FALSE ); if( nRet != SUCCESS ) ShowLeadError( nRet, NULL, NULL ); UpdateMenuStatus( GETCHILDDATA( hWnd ) ); InvalidateRect( hWnd, NULL, FALSE ); } /*---------------------------------------------------------------------------- | | Edit/Paste | ---------------------------------------------------------------------------*/ static L_VOID OnEditPaste ( HWND hWnd, L_INT nId ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_UINT32 dwFlags; L_INT nRet; if( nId == IDM_EDIT_PASTE_OBJECTS ) dwFlags = VECTOR_FLAGS_COPY_INTO_ACTIVE_LAYER; else dwFlags = VECTOR_FLAGS_COPY_LAYERS_ONLY; PushToUndoBuffer( hWnd ); Hourglass( TRUE ); nRet = L_VecCopyFromClipboard( hWnd, pData->pVector, dwFlags ); Hourglass( FALSE ); if( nRet != SUCCESS ) { ShowLeadError( nRet, NULL, NULL ); PopFromUndoBuffer( hWnd ); } UpdateMenuStatus( GETCHILDDATA( hWnd ) ); InvalidateRect( hWnd, NULL, FALSE ); } /*---------------------------------------------------------------------------- | | Edit/Delete | ---------------------------------------------------------------------------*/ static L_VOID OnEditDelete ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; PushToUndoBuffer( hWnd ); Hourglass( TRUE ); nRet = L_VecDeleteObject( pData->pVector, NULL, VECTOR_FLAGS_SELECTED_ONLY ); Hourglass( FALSE ); if( nRet != SUCCESS ) { ShowLeadError( nRet, NULL, NULL ); PopFromUndoBuffer( hWnd ); } UpdateMenuStatus( GETCHILDDATA( hWnd ) ); InvalidateRect( hWnd, NULL, FALSE ); } /*---------------------------------------------------------------------------- | | Edit/Select All | ---------------------------------------------------------------------------*/ static L_VOID OnEditSelectAll ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; ENUMDATA EnumData; memset( &EnumData, 0, sizeof( ENUMDATA ) ); EnumData.nType = ENUM_SELECTALL; Hourglass( TRUE ); nRet = L_VecEnumObjects( pData->pVector, MyEnumObjectsProc, &EnumData, 0L ); Hourglass( FALSE ); if( nRet != SUCCESS ) ShowLeadError( nRet, NULL, NULL ); UpdateMenuStatus( GETCHILDDATA( hWnd ) ); InvalidateRect( hWnd, NULL, FALSE ); } /*---------------------------------------------------------------------------- | | Edit/Unselect All | ---------------------------------------------------------------------------*/ static L_VOID OnEditUnselectAll ( HWND hWnd, L_BOOL bUpdate ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; ENUMDATA EnumData; memset( &EnumData, 0, sizeof( ENUMDATA ) ); EnumData.nType = ENUM_UNSELECTALL; Hourglass( TRUE ); nRet = L_VecEnumObjects( pData->pVector, MyEnumObjectsProc, &EnumData, 0L ); Hourglass( FALSE ); if( nRet != SUCCESS ) ShowLeadError( nRet, NULL, NULL ); if( bUpdate ) { UpdateMenuStatus( GETCHILDDATA( hWnd ) ); InvalidateRect( hWnd, NULL, FALSE ); } } /*---------------------------------------------------------------------------- | | View/Toolbar | ---------------------------------------------------------------------------*/ static L_VOID OnViewToolBar ( HWND hWnd ) { UNREFERENCED_PARAMETER( hWnd ); if ( g_bIsToolBarVisible ) { SendMessage( hwndRB, RB_SHOWBAND, 0, (LPARAM) FALSE ); g_bIsToolBarVisible = FALSE; } else { SendMessage( hwndRB, RB_SHOWBAND, 0, (LPARAM) TRUE ); g_bIsToolBarVisible = TRUE; } CHECKMENUITEM( g_hMenuChild, IDM_VIEW_TOOLBAR, g_bIsToolBarVisible ); } /*---------------------------------------------------------------------------- | | View/Scale | ---------------------------------------------------------------------------*/ static L_VOID OnViewScale ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); VECTORPOINT Scale; VECTORPOINT TempPoint; L_UINT32 dwFlags; L_INT nRet; L_VecGetScale( pData->pVector, &Scale ); dwFlags = VECTOR_DLG_AUTO_PROCESS | VECTOR_DLG_SHOW_PREVIEW | VECTOR_DLG_ENABLE_HELPBUTTON; if( L_VecIsObjectSelected( pData->pVector, NULL ) ) dwFlags |= VECTOR_DLG_SELECTED_ONLY; PushToUndoBuffer( hWnd ); memcpy( &TempPoint, &Scale, sizeof(VECTORPOINT) ); nRet = L_VecDlgScale( hWnd, pData->pVector, &Scale, NULL, dwFlags, VectorHelpCallback, NULL ); if( nRet == SUCCESS ) InvalidateRect( hWnd, NULL, FALSE ); else if( nRet != SUCCESS_DLG_CANCEL ) ShowLeadError( nRet, NULL, NULL ); /*if ( 0 == memcmp( &TempPoint, &Scale, sizeof(VECTORPOINT) ) ) PopFromUndoBuffer( hWnd );*/ UpdateMenuStatus( pData ); } /*---------------------------------------------------------------------------- | | View/Rotate | ---------------------------------------------------------------------------*/ static L_VOID OnViewRotate ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); VECTORPOINT Rotation; VECTORPOINT TempPoint; L_UINT32 dwFlags; L_INT nRet; L_VecGetRotation( pData->pVector, &Rotation ); dwFlags = VECTOR_DLG_AUTO_PROCESS | VECTOR_DLG_SHOW_PREVIEW | VECTOR_DLG_ENABLE_HELPBUTTON; if( L_VecIsObjectSelected( pData->pVector, NULL ) ) dwFlags |= VECTOR_DLG_SELECTED_ONLY; PushToUndoBuffer( hWnd ); memcpy( &TempPoint, &Rotation, sizeof(VECTORPOINT) ); nRet = L_VecDlgRotate( hWnd, pData->pVector, &Rotation, NULL, dwFlags, VectorHelpCallback, NULL ); if( nRet == SUCCESS ) InvalidateRect( hWnd, NULL, FALSE ); else if( nRet != SUCCESS_DLG_CANCEL ) ShowLeadError( nRet, NULL, NULL ); /*if ( 0 == memcmp( &TempPoint, &Rotation, sizeof(VECTORPOINT) ) ) PopFromUndoBuffer( hWnd );*/ UpdateMenuStatus( pData ); } /*---------------------------------------------------------------------------- | | View/Translate | ---------------------------------------------------------------------------*/ static L_VOID OnViewTranslate ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); VECTORPOINT Translation; VECTORPOINT TempPoint; L_UINT32 dwFlags; L_INT nRet; L_VecGetTranslation( pData->pVector, &Translation ); dwFlags = VECTOR_DLG_AUTO_PROCESS | VECTOR_DLG_SHOW_PREVIEW | VECTOR_DLG_ENABLE_HELPBUTTON; if( L_VecIsObjectSelected( pData->pVector, NULL ) ) dwFlags |= VECTOR_DLG_SELECTED_ONLY; PushToUndoBuffer( hWnd ); memcpy( &TempPoint, &Translation, sizeof(VECTORPOINT) ); nRet = L_VecDlgTranslate( hWnd, pData->pVector, &Translation, dwFlags, VectorHelpCallback, NULL ); if( nRet == SUCCESS ) InvalidateRect( hWnd, NULL, FALSE ); else if( nRet < 0 ) ShowLeadError( nRet, NULL, NULL ); /*if ( 0 == memcmp( &TempPoint, &Translation, sizeof(VECTORPOINT) ) ) PopFromUndoBuffer( hWnd );*/ UpdateMenuStatus( pData ); } /*---------------------------------------------------------------------------- | | View/Camera | ---------------------------------------------------------------------------*/ static L_VOID OnViewCamera ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); VECTORCAMERA Camera; VECTORCAMERA TempCamera; L_UINT32 dwFlags; L_INT nRet; L_VecGetCamera( pData->pVector, &Camera ); dwFlags = VECTOR_DLG_AUTO_PROCESS | VECTOR_DLG_SHOW_PREVIEW | VECTOR_DLG_ENABLE_HELPBUTTON; PushToUndoBuffer( hWnd ); memcpy( &TempCamera, &Camera, sizeof(VECTORCAMERA) ); nRet = L_VecDlgCamera( hWnd, pData->pVector, &Camera, dwFlags, VectorHelpCallback, NULL ); if( nRet == SUCCESS ) InvalidateRect( hWnd, NULL, FALSE ); else if( nRet != SUCCESS_DLG_CANCEL ) ShowLeadError( nRet, NULL, NULL ); if ( 0 == memcmp( &TempCamera, &Camera, sizeof(VECTORCAMERA) ) ) PopFromUndoBuffer( hWnd ); UpdateMenuStatus( pData ); } /*---------------------------------------------------------------------------- | | View/Mode | ---------------------------------------------------------------------------*/ static L_VOID OnViewMode ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nViewMode; L_INT nTemp; L_UINT32 dwFlags; L_INT nRet; nViewMode = L_VecGetViewMode( pData->pVector ); dwFlags = VECTOR_DLG_AUTO_PROCESS | VECTOR_DLG_SHOW_PREVIEW | VECTOR_DLG_ENABLE_HELPBUTTON; PushToUndoBuffer( hWnd ); nTemp = nViewMode; nRet = L_VecDlgViewMode( hWnd, pData->pVector, &nViewMode, dwFlags, VectorHelpCallback, NULL ); if( nRet == SUCCESS ) InvalidateRect( hWnd, NULL, FALSE ); else if( nRet != SUCCESS_DLG_CANCEL) ShowLeadError( nRet, NULL, NULL ); if ( nTemp == nViewMode ) PopFromUndoBuffer( hWnd ); UpdateMenuStatus( pData ); } /*---------------------------------------------------------------------------- | | View/Back Color | ---------------------------------------------------------------------------*/ static L_VOID OnViewBackColor ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); COLORREF clrTemp; COLORDLGPARAMS DlgParams; L_INT nRet; ZeroMemory( &DlgParams, sizeof( COLORDLGPARAMS ) ); DlgParams.crColor = BackgroundColor; DlgParams.uColorModel = 0; DlgParams.uColorSpace = DLG_COLOR_COLORSPACE_SHOW_RGB; DlgParams.uStructSize = sizeof( COLORDLGPARAMS ); DlgParams.uDlgFlags = (DLG_COLOR_SHOW_OLDCOLOR | DLG_COLOR_SHOW_NEWCOLOR | DLG_COLOR_SHOW_NAME | DLG_COLOR_COLORSPACE_SHOW_HUE | DLG_COLOR_COLORSPACE_SHOW_BRIGHTNESS | DLG_COLOR_COLORSPACE_SHOW_WHEEL | DLG_COLOR_COLORSPACE_SHOW_RGB | DLG_COLOR_COLORSPACE_SHOW_CMY | DLG_COLOR_COLORSPACE_SHOW_CMYK | DLG_COLOR_COLORSPACE_SHOW_LAB | DLG_COLOR_COLORMODEL_SHOW_RGB | DLG_COLOR_COLORMODEL_SHOW_HSB | DLG_COLOR_COLORMODEL_SHOW_HLS | DLG_COLOR_COLORMODEL_SHOW_CMY | DLG_COLOR_COLORMODEL_SHOW_CMYK | DLG_COLOR_COLORMODEL_SHOW_LAB ); nRet = L_DlgColor(g_hWndFrame,&DlgParams); if(nRet == SUCCESS_DLG_OK) { BackgroundColor = DlgParams.crColor ; L_VecSetBackgroundColor( pData->pVector, BackgroundColor); InvalidateRect( hWnd, NULL, FALSE ); } if ( 0 == memcmp( &clrTemp, &BackgroundColor, sizeof(COLORREF) ) ) PopFromUndoBuffer( hWnd ); UpdateMenuStatus( pData ); } /*---------------------------------------------------------------------------- | | View/Extent | ---------------------------------------------------------------------------*/ static L_VOID OnViewExtent ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; VECTORPOINT Scale; VECTORPOINT Rotation; VECTORPOINT Translation; POINT pt; Scale.x = Scale.y = Scale.z = 1.0; nRet = L_VecSetScale( pData->pVector, &Scale, NULL, NULL, 0L ); Rotation.x = Rotation.y = Rotation.z = 0.0; nRet = L_VecSetRotation( pData->pVector, &Rotation, NULL, NULL, 0L ); Translation.x = Translation.y = Translation.z = 0.0; nRet = L_VecSetTranslation( pData->pVector, &Translation, NULL, 0L ); pt.x = 0; pt.y = 0; L_VecSetPan( pData->pVector, &pt ); L_VecSetParallelogram( pData->pVector, NULL, NULL ); L_VecSetOrigin( pData->pVector, NULL ); L_VecSetCamera( pData->pVector, NULL ); if( L_VecGetEngine( pData->pVector ) == VECTOR_ENGINE_GDI ) { SetScrollRange( hWnd, SB_HORZ, 0, 2, TRUE ); SetScrollPos( hWnd, SB_HORZ, 1, TRUE ); SetScrollRange( hWnd, SB_VERT, 0, 2, TRUE ); SetScrollPos( hWnd, SB_VERT, 1, TRUE ); } UpdateScrollBars( hWnd ); InvalidateRect( hWnd, NULL, FALSE ); } /*---------------------------------------------------------------------------- | | Object/Explode | ---------------------------------------------------------------------------*/ static L_VOID OnObjectExplode ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; PushToUndoBuffer( hWnd ); Hourglass( TRUE ); nRet = L_VecExplodeObject( pData->pVector, NULL, VECTOR_FLAGS_SELECTED_ONLY ); Hourglass( FALSE ); if( nRet != SUCCESS ) ShowLeadError( nRet, NULL, NULL ); UpdateMenuStatus( pData ); InvalidateRect( hWnd, NULL, FALSE ); } /*---------------------------------------------------------------------------- | | Layer/Edit | ---------------------------------------------------------------------------*/ static L_VOID OnLayerEdit ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; PushToUndoBuffer( hWnd ); nRet = L_VecDlgEditAllLayers( hWnd, pData->pVector, VECTOR_DLG_ENABLE_HELPBUTTON, VectorHelpCallback, NULL ); if( nRet == SUCCESS ) { OnEditUnselectAll( hWnd, FALSE ); InvalidateRect( hWnd, NULL, FALSE ); UpdateMenuStatus( pData ); } else if( nRet != SUCCESS_DLG_CANCEL ) ShowLeadError( nRet, NULL, NULL ); if ( SUCCESS != nRet ) PopFromUndoBuffer( hWnd ); UpdateMenuStatus( pData ); } /*---------------------------------------------------------------------------- | | Group/Edit | ---------------------------------------------------------------------------*/ static L_VOID OnGroupEdit ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; PushToUndoBuffer( hWnd ); nRet = L_VecDlgEditAllGroups( hWnd, pData->pVector, VECTOR_DLG_ENABLE_HELPBUTTON, VectorHelpCallback, NULL ); if( nRet == SUCCESS ) { InvalidateRect( hWnd, NULL, FALSE ); UpdateMenuStatus( pData ); } else if( nRet != SUCCESS_DLG_CANCEL ) ShowLeadError( nRet, NULL, NULL ); if ( SUCCESS != nRet ) PopFromUndoBuffer( hWnd ); UpdateMenuStatus( pData ); } /*---------------------------------------------------------------------------- | | Group/Add | ---------------------------------------------------------------------------*/ static L_VOID OnGroupAdd ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); GROUPSDLGDATA GroupsDlgData; L_INT nRet; ENUMDATA EnumData; PushToUndoBuffer( hWnd ); GroupsDlgData.pVector = pData->pVector; if( DoDialogBoxParam( IDD_GROUPS, hWnd, (DLGPROC) GroupsDlgProc, (LPARAM) &GroupsDlgData ) == IDOK ) { EnumData.nType = ENUM_ADDTOGROUP; EnumData.pGroup = &GroupsDlgData.Group; Hourglass( TRUE ); nRet = L_VecEnumObjects( pData->pVector, MyEnumObjectsProc, &EnumData, VECTOR_FLAGS_SELECTED_ONLY ); Hourglass( FALSE ); if( nRet != SUCCESS ) ShowLeadError( nRet, NULL, NULL ); } else { PopFromUndoBuffer( hWnd ); UpdateMenuStatus( pData ); } } /*---------------------------------------------------------------------------- | | Object/New | ---------------------------------------------------------------------------*/ static L_VOID OnObjectNew ( HWND hWnd, L_INT nId ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet, nType; VECTOROBJECT Object; switch( nId ) { case IDM_OBJECT_NEW_VERTEX: nType = VECTOR_VERTEX; break; case IDM_OBJECT_NEW_LINE: nType = VECTOR_LINE; break; case IDM_OBJECT_NEW_RECTANGLE: nType = VECTOR_RECTANGLE; break; case IDM_OBJECT_NEW_POLYLINE: nType = VECTOR_POLYLINE; break; case IDM_OBJECT_NEW_POLYBEZIER: nType = VECTOR_POLYBEZIER; break; case IDM_OBJECT_NEW_POLYGON: nType = VECTOR_POLYGON; break; case IDM_OBJECT_NEW_ELLIPSE: nType = VECTOR_ELLIPSE; break; case IDM_OBJECT_NEW_CIRCLE: nType = VECTOR_CIRCLE; break; case IDM_OBJECT_NEW_ARC: nType = VECTOR_ARC; break; case IDM_OBJECT_NEW_ELLIPTICALARC: nType = VECTOR_ELLIPTICALARC; break; case IDM_OBJECT_NEW_TEXT: nType = VECTOR_TEXT; break; case IDM_OBJECT_NEW_PIE: nType = VECTOR_PIE; break; case IDM_OBJECT_NEW_CHORD: nType = VECTOR_CHORD; break; case IDM_OBJECT_NEW_POLYDRAW: nType = VECTOR_POLYDRAW; break; case IDM_OBJECT_NEW_RASTER: nType = VECTOR_RASTER; break; case IDM_OBJECT_NEW_CLONE: nType = VECTOR_CLONE; break; case IDM_OBJECT_NEW_SPLINE: nType = VECTOR_SPLINE; break; case IDM_OBJECT_NEW_HPOLYBEZIER: nType = VECTOR_HPOLYBEZIER; break; default: return; } PushToUndoBuffer( hWnd ); nRet = L_VecDlgNewObject( hWnd, pData->pVector, NULL, nType, NULL, &Object, VECTOR_DLG_AUTO_PROCESS | VECTOR_DLG_ENABLE_HELPBUTTON, VectorHelpCallback, hWnd ); if( nRet == SUCCESS ) { // OnEditUnselectAll( hWnd, FALSE ); // L_VecSelectObject( pData->pVector, &Object, TRUE ); UpdateMenuStatus( pData ); InvalidateRect( hWnd, NULL, FALSE ); UpdateScrollBars( hWnd ); } else if( nRet != ERROR_USER_ABORT ) ShowLeadError( nRet, NULL, NULL ); if ( SUCCESS != nRet ) { PopFromUndoBuffer( hWnd ); UpdateMenuStatus( pData ); } } /*---------------------------------------------------------------------------- | | Object/Properties | ---------------------------------------------------------------------------*/ static L_VOID OnObjectProperties ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); ENUMDATA EnumData; L_INT nRet; L_CHAR Object1[ VECTOR_OBJECT_BUFFER_SIZE ]; L_CHAR Object2[ VECTOR_OBJECT_BUFFER_SIZE ]; L_BOOL bIsDifferent = FALSE; EnumData.nType = ENUM_COUNT; EnumData.nObjectCount = 0; nRet = L_VecEnumObjects( pData->pVector, MyEnumObjectsProc, &EnumData, VECTOR_FLAGS_SELECTED_ONLY ); if( nRet != SUCCESS || EnumData.nObjectCount != 1 ) { return; } // Object status before the properties dialog ZeroMemory( Object1, sizeof(Object1) ); nRet = L_VecGetObject( pData->pVector, &EnumData.LastObject, EnumData.LastObject.nType, Object1 ); PushToUndoBuffer( hWnd ); nRet = L_VecDlgEditObject( hWnd, pData->pVector, &EnumData.LastObject, EnumData.LastObject.nType, NULL, VECTOR_DLG_AUTO_PROCESS | VECTOR_DLG_ENABLE_HELPBUTTON, VectorHelpCallback, NULL ); if( nRet == SUCCESS ) { // Object status after the properties dialog { ZeroMemory( Object2, sizeof(Object2) ); nRet = L_VecGetObject( pData->pVector, &EnumData.LastObject, EnumData.LastObject.nType, Object2 ); bIsDifferent = CompareObjects( Object1, Object2, EnumData.LastObject.nType ); } } else if( nRet != SUCCESS_DLG_CANCEL ) ShowLeadError( nRet, NULL, NULL ); if ( ! bIsDifferent ) PopFromUndoBuffer( hWnd ); UpdateMenuStatus( pData ); InvalidateRect( hWnd, NULL, TRUE ); } /*---------------------------------------------------------------------------- | | Options/Bind Mode/Bind Vertices | Options/Bind Mode/Unbind Vertices | ---------------------------------------------------------------------------*/ static L_VOID OnOptionsBindMode ( HWND hWnd, L_INT nId ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; nRet = L_VecSetBindVerticesMode( pData->pVector, ( nId == IDM_OPTIONS_BINDMODE_BINDVERTICES ) ? VECTOR_BIND_VERTICES : VECTOR_UNBIND_VERTICES ); if( nRet != SUCCESS ) ShowLeadError( nRet, NULL, NULL ); UpdateMenuStatus( pData ); InvalidateRect( hWnd, NULL, FALSE ); } /*---------------------------------------------------------------------------- | | Options/Hit Test | ---------------------------------------------------------------------------*/ static L_VOID OnOptionsHitTest ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); VECTORHITTEST HitTest; L_INT nRet; L_VecGetHitTest( pData->pVector, &HitTest ); nRet = L_VecDlgHitTest( hWnd, pData->pVector, &HitTest, VECTOR_DLG_AUTO_PROCESS | VECTOR_DLG_ENABLE_HELPBUTTON, VectorHelpCallback, NULL ); if( nRet != SUCCESS && nRet != SUCCESS_DLG_CANCEL ) ShowLeadError( nRet, NULL, NULL ); } /*---------------------------------------------------------------------------- | | Options/Render | ---------------------------------------------------------------------------*/ static L_VOID OnOptionsRender ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_BOOL bUseLights; COLORREF ColorAmbient; L_INT nPolygonMode; L_INT nRet; bUseLights = L_VecGetUseLights( pData->pVector ); ColorAmbient = L_VecGetAmbientColor( pData->pVector ); nPolygonMode = L_VecGetPolygonMode( pData->pVector ); nRet = L_VecDlgRender( hWnd, pData->pVector, &bUseLights, &ColorAmbient, &nPolygonMode, VECTOR_DLG_AUTO_PROCESS | VECTOR_DLG_SHOW_PREVIEW | VECTOR_DLG_ENABLE_HELPBUTTON, VectorHelpCallback, NULL ); if( nRet == SUCCESS ) InvalidateRect( hWnd, NULL, FALSE ); else if( nRet != SUCCESS_DLG_CANCEL ) ShowLeadError( nRet, NULL, NULL ); } /*---------------------------------------------------------------------------- | | Options/Apply Transformation | ---------------------------------------------------------------------------*/ static L_VOID OnOptionsApplyTransformation ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; nRet = L_VecApplyTransformation( pData->pVector ); if( nRet != SUCCESS ) ShowLeadError( nRet, NULL, NULL ); InvalidateRect( hWnd, NULL, FALSE ); } /*---------------------------------------------------------------------------- | | OnOptionsInvertColors | ---------------------------------------------------------------------------*/ static L_VOID OnOptionsInvertColors ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; nRet = L_VecInvertColors( pData->pVector ); if( nRet != SUCCESS ) ShowLeadError( nRet, NULL, NULL ); InvalidateRect( hWnd, NULL, FALSE ); } /*---------------------------------------------------------------------------- | | OnOptionsPalette | ---------------------------------------------------------------------------*/ static L_VOID OnOptionsPalette ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; WORD i; WORD k; PALETTEINFO PaletteInfo; LPLOGPALETTE pLogPalette; HPALETTE hPalette; PALETTEENTRY PalEnt[ 256 ]; ZeroMemory( &PaletteInfo, sizeof( PaletteInfo ) ); hPalette = L_VecGetPalette( pData->pVector ); if( NULL != hPalette ) { /* get palette entries and load them to the Palette info structure */ GetPaletteEntries( hPalette, 0, sizeof( PalEnt ) / sizeof( PalEnt[ 0 ] ), PalEnt ); /* search the palette to see how many actual item exist */ PaletteInfo.uCount = sizeof( PalEnt ) / sizeof( PalEnt[ 0 ] ); PaletteInfo.prgbList = malloc( sizeof( COLORREF ) * PaletteInfo.uCount ); for( i = 1 ; i < sizeof( PalEnt ) / sizeof( PalEnt[ 0 ] ) ; i++ ) { if( PalEnt[ i ].peRed == PalEnt[ i - 1 ].peRed && PalEnt[ i ].peGreen == PalEnt[ i - 1 ].peGreen && PalEnt[ i ].peBlue == PalEnt[ i - 1 ].peBlue ) { PaletteInfo.uCount = i; break; } else { PaletteInfo.prgbList[ i - 1 ] = RGB( PalEnt[ i - 1 ].peRed, PalEnt[ i - 1 ].peGreen, PalEnt[ i - 1 ].peBlue ); } } PaletteInfo.prgbList[ i - 1 ] = RGB( PalEnt[ i - 1 ].peRed, PalEnt[ i - 1 ].peGreen, PalEnt[ i - 1 ].peBlue ); } PushToUndoBuffer( hWnd ); nRet = DialogBoxParam( g_hInstance, MAKEINTRESOURCE( IDD_PALETTE ), g_hWndFrame, (DLGPROC)PaletteProc, (LPARAM)&PaletteInfo ); if( SUCCESS == nRet ) { if( PaletteInfo.uCount > 0 ) { pLogPalette = (LPLOGPALETTE) malloc( sizeof( LOGPALETTE ) + sizeof( PALETTEENTRY ) * 255 ); if( NULL != pLogPalette ) { pLogPalette->palVersion = 0x300; pLogPalette->palNumEntries = 256; for( i = 0 ; i < pLogPalette->palNumEntries ; i++ ) { if( i < PaletteInfo.uCount ) { k = i; } else { k = (WORD)( PaletteInfo.uCount - 1 ); } pLogPalette->palPalEntry[ i ].peRed = GetRValue( PaletteInfo.prgbList[ k ] ); pLogPalette->palPalEntry[ i ].peGreen = GetGValue( PaletteInfo.prgbList[ k ] ); pLogPalette->palPalEntry[ i ].peBlue = GetBValue( PaletteInfo.prgbList[ k ] ); pLogPalette->palPalEntry[ i ].peFlags = 0; } hPalette = CreatePalette( pLogPalette ); if( NULL != hPalette ) { nRet = L_VecSetPalette( pData->pVector, hPalette ); DeleteObject( hPalette ); if( SUCCESS != nRet ) { ShowLeadError( nRet, NULL, NULL ); } } free( pLogPalette ); } free( PaletteInfo.prgbList ); } else { L_VecSetPalette( pData->pVector, NULL ); } } /*else { PopFromUndoBuffer( hWnd ); }*/ UpdateMenuStatus( pData ); InvalidateRect( hWnd, NULL, TRUE ); } /*---------------------------------------------------------------------------- | | MyEnumObjectsProc | ---------------------------------------------------------------------------*/ static L_INT EXT_CALLBACK MyEnumObjectsProc ( pVECTORHANDLE pVector, const pVECTOROBJECT pObject, L_VOID *pUserData ) { LPENUMDATA pEnumData = (LPENUMDATA) pUserData; L_INT nRet; L_CHAR pBuffer[ VECTOR_OBJECT_BUFFER_SIZE ]; switch( pEnumData->nType ) { case ENUM_COUNT: pEnumData->nObjectCount++; nRet = SUCCESS; break; case ENUM_SELECTALL: if( !L_VecIsObjectSelected( pVector, pObject ) ) { nRet = L_VecSelectObject( pVector, pObject, TRUE ); pEnumData->bNeedPaint = TRUE; } else nRet = SUCCESS; break; case ENUM_UNSELECTALL: if( L_VecIsObjectSelected( pVector, pObject ) ) { nRet = L_VecSelectObject( pVector, pObject, FALSE ); pEnumData->bNeedPaint = TRUE; } else nRet = SUCCESS; break; case ENUM_SELECTRECT: if( L_VecIsObjectInsideRect( pVector, pObject, &pEnumData->Rect, 0L ) && !L_VecIsObjectSelected( pVector, pObject ) ) { nRet = L_VecSelectObject( pVector, pObject, TRUE ); pEnumData->bNeedPaint = TRUE; } else nRet = SUCCESS; break; case ENUM_ADDTOGROUP: nRet = L_VecGetObject( pVector, pObject, pObject->nType, pBuffer ); if( nRet == SUCCESS ) { nRet = L_VecAddObjectToGroup( pVector, pEnumData->pGroup, pObject->nType, pBuffer, NULL ); L_VecFreeObject( pObject->nType, pBuffer ); } break; default: nRet = SUCCESS; } memcpy( &pEnumData->LastObject, pObject, sizeof( VECTOROBJECT ) ); return nRet; } /*---------------------------------------------------------------------------- | | DisplayTitle | ---------------------------------------------------------------------------*/ static L_VOID DisplayTitle ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); SetWindowText( hWnd, pData->szFileName ); } /*---------------------------------------------------------------------------- | | UpdateScrollBars | ---------------------------------------------------------------------------*/ static L_VOID UpdateScrollBars ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); RECT rcDraw; POINT ptPan; L_INT nOldMax, nOldPos, nNewMax, nNewPos; L_INT cxDraw, cyDraw; if( L_VecGetEngine( pData->pVector) != VECTOR_ENGINE_GDI ) return; L_VecGetPan( pData->pVector, &ptPan ); L_VecGetObjectRect( pData->pVector, NULL, &rcDraw, 0L ); rcDraw.left += abs( ptPan.x ); rcDraw.top += abs( ptPan.y ); rcDraw.right += abs( ptPan.x ); rcDraw.bottom += abs( ptPan.y ); cxDraw = rcDraw.right - rcDraw.left; cyDraw = rcDraw.bottom - rcDraw.top; nNewMax = cxDraw; GetScrollRange( hWnd, SB_HORZ, &nOldPos, &nOldMax ); nOldPos = GetScrollPos( hWnd, SB_HORZ ); if( nOldMax != 0 ) nNewPos = nNewMax * nOldPos / nOldMax; else nNewPos = nNewMax / 2; SetScrollRange( hWnd, SB_HORZ, 0, nNewMax, TRUE ); SetScrollPos( hWnd, SB_HORZ, nNewPos, TRUE ); nNewMax = cyDraw; GetScrollRange( hWnd, SB_VERT, &nOldPos, &nOldMax ); nOldPos = GetScrollPos( hWnd, SB_VERT ); if( nOldMax != 0 ) nNewPos = nNewMax * nOldPos / nOldMax; else nNewPos = nNewMax / 2; SetScrollRange( hWnd, SB_VERT, 0, nNewMax, TRUE ); SetScrollPos( hWnd, SB_VERT, nNewPos, TRUE ); } /*---------------------------------------------------------------------------- | | DrawCaptureRect | ---------------------------------------------------------------------------*/ static L_VOID DrawCaptureRect ( HWND hWnd, LPCHILDDATA pData ) { HDC hDC; HPEN hPenOld; HBRUSH hBrushOld; hDC = GetDC( hWnd ); hPenOld = SelectObject( hDC, CreatePen( PS_DOT, 1, RGB( 0xFF, 0xFF, 0xFF ) ) ); hBrushOld = SelectObject( hDC, GetStockObject( NULL_BRUSH ) ); SetROP2( hDC, R2_XORPEN ); Rectangle( hDC, pData->rcCapture.left, pData->rcCapture.top, pData->rcCapture.right, pData->rcCapture.bottom ); SelectObject( hDC, hBrushOld ); DeleteObject( SelectObject( hDC, hPenOld ) ); ReleaseDC( hWnd, hDC ); } /*---------------------------------------------------------------------------- | | UpdateMenuStatus | ---------------------------------------------------------------------------*/ static L_VOID UpdateMenuStatus ( LPCHILDDATA pData ) { L_BOOL bAnyObjectSelected, bCanPaste, bAnyObjects, bCanEditObject; L_INT nBindMode; ENUMDATA EnumData; bAnyObjectSelected = L_VecIsObjectSelected( pData->pVector, NULL ); bAnyObjects = !L_VecIsEmpty( pData->pVector ); bCanPaste = L_VecClipboardReady(); nBindMode = L_VecGetBindVerticesMode( pData->pVector ); EnumData.nType = ENUM_COUNT; EnumData.nObjectCount = 0; L_VecEnumObjects( pData->pVector, MyEnumObjectsProc, &EnumData, VECTOR_FLAGS_SELECTED_ONLY ); bCanEditObject = EnumData.nObjectCount == 1; ENABLEMENUITEM( g_hMenuChild, IDM_FILE_NEW, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_FILE_SAVE, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_EDIT_UNDO, pData->UndoData.nNumberOfActions > 0 ); ENABLEMENUITEM( g_hMenuChild, IDM_EDIT_CUT, bAnyObjectSelected && !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_EDIT_COPY, bAnyObjectSelected && !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_EDIT_PASTE_OBJECTS, bCanPaste && !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_EDIT_PASTE_LAYERS, bCanPaste && !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_EDIT_DELETE, bAnyObjectSelected && !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_EDIT_SELECTALL, bAnyObjects && !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_EDIT_UNSELECTALL, bAnyObjectSelected && !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_LAYER_EDIT, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_GROUP_EDIT, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_GROUP_ADD, bAnyObjectSelected && L_VecGetGroupCount( pData->pVector ) >= 1 && !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_VERTEX, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_LINE, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_RECTANGLE, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_POLYLINE, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_POLYBEZIER, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_POLYGON, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_ELLIPSE, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_CIRCLE, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_ARC, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_ELLIPTICALARC, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_TEXT, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_PIE, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_CHORD, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_POLYDRAW, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_RASTER, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_NEW_CLONE, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_EXPLODE, bAnyObjectSelected && !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OBJECT_PROPERTIES, bCanEditObject && !g_bViewOnly ); CheckMenuRadioItem( g_hMenuChild, IDM_OPTIONS_BINDMODE_BINDVERTICES, IDM_OPTIONS_BINDMODE_UNBINDVERTICES, ( nBindMode == VECTOR_BIND_VERTICES ) ? IDM_OPTIONS_BINDMODE_BINDVERTICES : IDM_OPTIONS_BINDMODE_UNBINDVERTICES, MF_BYCOMMAND ); ENABLEMENUITEM( g_hMenuChild, IDM_OPTIONS_BINDMODE_BINDVERTICES, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OPTIONS_BINDMODE_UNBINDVERTICES, !g_bViewOnly ); ENABLEMENUITEM( g_hMenuChild, IDM_OPTIONS_APPLYTRANSFORMATION, !g_bViewOnly ); } /*---------------------------------------------------------------------------- | | SaveVector | ---------------------------------------------------------------------------*/ static L_INT SaveVector ( const pVECTORHANDLE pVector, const L_TCHAR *pszFile, L_INT nFormat ) { SAVEFILEOPTION SaveFileOption; L_INT nRet; Hourglass( TRUE ); memset( &SaveFileOption, 0, sizeof( SAVEFILEOPTION ) ); SaveFileOption.uStructSize = sizeof( SAVEFILEOPTION ); nRet = L_VecSaveFile( (L_TCHAR*) pszFile, pVector, nFormat, &SaveFileOption ); Hourglass( FALSE ); if( nRet != SUCCESS ) ShowLeadError( nRet, TEXT("Save Vector File"), pszFile ); return nRet; } /*---------------------------------------------------------------------------- | | GroupsDlgProc | ---------------------------------------------------------------------------*/ static L_BOOL EXT_FUNCTION GroupsDlgProc ( HWND hWnd, L_UINT uMessage, WPARAM wParam, LPARAM lParam ) { static LPGROUPSDLGDATA pGroupsDlgData; HWND hWndList; L_INT nCount, i, nIndex, nRet; VECTORGROUP Group; VECTORGROUPDESC GroupDesc; switch( uMessage ) { case WM_INITDIALOG: pGroupsDlgData = (LPGROUPSDLGDATA) lParam; hWndList = GetDlgItem( hWnd, IDC_GROUPS ); nCount = L_VecGetGroupCount( pGroupsDlgData->pVector ); for( i = 0; i < nCount; i++ ) { L_VecGetGroupByIndex( pGroupsDlgData->pVector, i, &Group ); L_VecGetGroup( pGroupsDlgData->pVector, &Group, &GroupDesc ); nIndex = ListBox_AddString( hWndList, GroupDesc.szName ); L_VecFreeGroup( &GroupDesc ); ListBox_SetItemData( hWndList, nIndex, i ); } ListBox_SetCurSel( hWndList, 0 ); return TRUE; case WM_COMMAND: switch( LOWORD( wParam ) ) { case IDOK: hWndList = GetDlgItem( hWnd, IDC_GROUPS ); nIndex = ListBox_GetCurSel( hWndList ); nRet = L_VecGetGroupByIndex( pGroupsDlgData->pVector, ListBox_GetItemData( hWndList, nIndex ), &pGroupsDlgData->Group ); if( nRet != SUCCESS ) { ShowLeadError( nRet, NULL, NULL ); return TRUE; } case IDCANCEL: EndDialog( hWnd, LOWORD( wParam ) ); return TRUE; } break; default: break; } return FALSE; } /*---------------------------------------------------------------------------- | | ResolveProc | ---------------------------------------------------------------------------*/ static L_BOOL EXT_FUNCTION ResolveProc ( HWND hWnd, L_UINT uMsg, WPARAM wParam, LPARAM lParam ) { VECTORLINKDESC Target; LPPROPSHEETPAGE pPar; LPCHILDDATA pData; pVECTOROBJECT pObj; HRESULT hResult; L_UINT32 uCount; L_UINT32 i; L_CHAR szBuffer[ 7 + L_MAXPATH ]; switch( uMsg ) { case WM_INITDIALOG: pPar = (LPPROPSHEETPAGE)lParam; pData = (LPCHILDDATA)pPar->lParam; pObj = &pData->ChildEx.LinkObj; if( NULL != pObj ) { uCount = L_VecGetHyperlinkCount( pData->pVector, pObj ); for( i = 0 ; i < uCount ; i++ ) { if( SUCCESS == L_VecGetHyperlink( pData->pVector, pObj, i, &Target ) ) { /* form the information in a readable way */ if( TRUE == Target.bObject ) { sprintf( szBuffer, "Object target with handle %x", pObj ); } else { sprintf( szBuffer, "file: %s", Target.tar.fileobject.target.szPath ); } ListBox_AddString( GetDlgItem( hWnd, IDC_TARGETLIST ), szBuffer ); } } } return TRUE; case WM_COMMAND: switch( LOWORD( wParam ) ) { case IDOK: hResult = ListBox_GetCurSel( GetDlgItem( hWnd, IDC_TARGETLIST ) ); EndDialog( hWnd, hResult ); return TRUE; case IDCANCEL: EndDialog( hWnd, LB_ERR ); return TRUE; } return FALSE; case WM_SYSCOMMAND: if( SC_CLOSE == wParam ) { EndDialog( hWnd, -1 ); return TRUE; } else { return FALSE; } } return FALSE; } /*---------------------------------------------------------------------------- | | PaletteProc | ---------------------------------------------------------------------------*/ static L_BOOL EXT_FUNCTION PaletteProc ( HWND hWnd, L_UINT uMsg, WPARAM wParam, LPARAM lParam ) { static pPALETTEINFO pPaletteInfo; static COLORREF CusColors[ 16 ]; static HWND hList; LPMEASUREITEMSTRUCT pMeasure; LPDRAWITEMSTRUCT pDrawItem; HBRUSH hOldBrush; COLORREF rgbValue; L_INT nIndex; L_UINT j; L_CHAR szBuffer[ 20 ]; COLORDLGPARAMS DlgParams; L_INT nRet; LOGBRUSH LogBrush; LOGPEN LogPen; HPEN hOldPen; switch( uMsg ) { case WM_INITDIALOG: pPaletteInfo = (pPALETTEINFO) lParam; hList = GetDlgItem( hWnd, IDC_PALETTE_LIST ); for( j = 0 ; j < pPaletteInfo->uCount ; j++ ) { nIndex = ListBox_AddString( hList, "" ); ListBox_SetItemData( hList, nIndex, pPaletteInfo->prgbList[ j ] ); } return TRUE; case WM_MEASUREITEM: pMeasure = (LPMEASUREITEMSTRUCT)lParam; pMeasure->itemHeight = 20; return TRUE; case WM_DRAWITEM: if( IDC_PALETTE_LIST == wParam ) { pDrawItem = (LPDRAWITEMSTRUCT)lParam; if( ODT_LISTBOX == pDrawItem->CtlType && -1 != pDrawItem->itemID ) { rgbValue = ListBox_GetItemData( hList, pDrawItem->itemID ); SetBkMode( pDrawItem->hDC, TRANSPARENT ); SetTextAlign( pDrawItem->hDC, TA_CENTER ); SetTextColor( pDrawItem->hDC, RGB( 255 - GetRValue( rgbValue ), 255 - GetGValue( rgbValue ), 255 - GetBValue( rgbValue ) ) ); hOldBrush = (HBRUSH)SelectObject( pDrawItem->hDC, CreateSolidBrush( rgbValue ) ); Rectangle( pDrawItem->hDC, 0, pDrawItem->rcItem.top, pDrawItem->rcItem.right, pDrawItem->rcItem.bottom ); sprintf( szBuffer, "0x%02X%02X%02X", GetRValue( rgbValue ), GetGValue( rgbValue ), GetBValue( rgbValue ) ); TextOutA( pDrawItem->hDC, pDrawItem->rcItem.right / 2, ( pDrawItem->rcItem.bottom + pDrawItem->rcItem.top ) / 2 - 5 , szBuffer, strlen( szBuffer ) ); if ( pDrawItem->itemState & ODS_SELECTED ) { ZeroMemory( &LogBrush, sizeof(LOGBRUSH) ); LogBrush.lbStyle = BS_NULL; ZeroMemory( &LogPen, sizeof(LOGPEN) ); LogPen.lopnStyle = PS_SOLID; LogPen.lopnColor = (COLORREF) GetSysColor(COLOR_HIGHLIGHT); LogPen.lopnWidth.x = 1; LogPen.lopnWidth.y = 0; SelectObject( pDrawItem->hDC, CreateBrushIndirect( &LogBrush ) ); hOldPen = (HPEN)SelectObject( pDrawItem->hDC, CreatePenIndirect( &LogPen ) ); Rectangle( pDrawItem->hDC, pDrawItem->rcItem.left+1, pDrawItem->rcItem.top+1, pDrawItem->rcItem.right-1, pDrawItem->rcItem.bottom-1 ); DeleteObject( SelectObject( pDrawItem->hDC, hOldPen ) ); } DeleteObject( SelectObject( pDrawItem->hDC, hOldBrush ) ); return TRUE; } } break; case WM_COMMAND: switch( LOWORD( wParam ) ) { case IDOK: pPaletteInfo->uCount = ListBox_GetCount( hList ); pPaletteInfo->prgbList = (COLORREF *)realloc( pPaletteInfo->prgbList, sizeof( COLORREF ) * pPaletteInfo->uCount ); if( NULL == pPaletteInfo->prgbList ) { EndDialog( hWnd, ERROR_NO_MEMORY ); } else { for( j = 0 ; j < pPaletteInfo->uCount ; j++ ) { pPaletteInfo->prgbList[ j ] = ListBox_GetItemData( hList, j ); } } EndDialog( hWnd, SUCCESS ); return TRUE; case IDCANCEL: EndDialog( hWnd, SUCCESS_DLG_CANCEL ); return TRUE; case IDC_PALETTE_ADD: ZeroMemory( &DlgParams, sizeof( COLORDLGPARAMS ) ); DlgParams.crColor = RGB( 0, 0, 0 ); DlgParams.uColorModel = 0; DlgParams.uColorSpace = DLG_COLOR_COLORSPACE_SHOW_RGB; DlgParams.uStructSize = sizeof( COLORDLGPARAMS ); DlgParams.uDlgFlags = ( DLG_COLOR_SHOW_OLDCOLOR | DLG_COLOR_SHOW_NEWCOLOR | DLG_COLOR_SHOW_NAME | DLG_COLOR_COLORSPACE_SHOW_HUE | DLG_COLOR_COLORSPACE_SHOW_BRIGHTNESS | DLG_COLOR_COLORSPACE_SHOW_WHEEL | DLG_COLOR_COLORSPACE_SHOW_RGB | DLG_COLOR_COLORSPACE_SHOW_CMY | DLG_COLOR_COLORSPACE_SHOW_CMYK | DLG_COLOR_COLORSPACE_SHOW_LAB | DLG_COLOR_COLORMODEL_SHOW_RGB | DLG_COLOR_COLORMODEL_SHOW_HSB | DLG_COLOR_COLORMODEL_SHOW_HLS | DLG_COLOR_COLORMODEL_SHOW_CMY | DLG_COLOR_COLORMODEL_SHOW_CMYK | DLG_COLOR_COLORMODEL_SHOW_LAB ); nRet = L_DlgColor(g_hWndFrame,&DlgParams); if(nRet == SUCCESS_DLG_OK) { nIndex = ListBox_AddString( hList, "" ); ListBox_SetItemData( hList, nIndex, DlgParams.crColor ); } return TRUE; case IDC_PALETTE_REMOVE: nIndex = ListBox_GetCurSel( hList ); if( LB_ERR != nIndex ) { ListBox_DeleteString( hList, nIndex ); Button_Enable( GetDlgItem( hWnd, IDC_PALETTE_REMOVE ), FALSE ); } break; case IDC_PALETTE_LIST: nIndex = ListBox_GetCurSel( hList ); Button_Enable( GetDlgItem( hWnd, IDC_PALETTE_REMOVE ), LB_ERR != nIndex ); return TRUE; } } return FALSE; } /*---------------------------------------------------------------------------- | | ConvertToProc | ---------------------------------------------------------------------------*/ static L_BOOL EXT_FUNCTION ConvertToProc ( HWND hWnd, L_UINT uMessage, WPARAM wParam, LPARAM lParam ) { L_TCHAR szFileName[ L_MAXPATH ] = TEXT(""); OPENFILENAME SaveFileName; static pCONVERTDATA pConvert; HENHMETAFILE hEnhMetaFile = NULL; HMETAFILE hMetaFile = NULL; HENHMETAFILE hEnhMetaFile2 = NULL; HMETAFILE hMetaFile2 = NULL; OSVERSIONINFO OsVersionInfo; switch( uMessage ) { case WM_INITDIALOG: pConvert = (pCONVERTDATA)lParam; SetDlgItemInt( hWnd, IDC_CONVERT_LEFT , pConvert->Rect.left , FALSE ); SetDlgItemInt( hWnd, IDC_CONVERT_TOP , pConvert->Rect.top , FALSE ); SetDlgItemInt( hWnd, IDC_CONVERT_RIGHT , pConvert->Rect.right , FALSE ); SetDlgItemInt( hWnd, IDC_CONVERT_BOTTOM, pConvert->Rect.bottom, FALSE ); SetDlgItemInt( hWnd, IDC_CONVERT_DPI, pConvert->uDPI, FALSE ); SetDlgItemText( hWnd, IDC_CONVERT_PATH, pConvert->szFileName ); return TRUE; case WM_COMMAND: switch( LOWORD( wParam ) ) { case IDOK: /* fill information and exit */ GetDlgItemText( hWnd, IDC_CONVERT_PATH, pConvert->szFileName, sizeof( pConvert->szFileName ) / sizeof( L_TCHAR ) ); if( 0 == pConvert->szFileName[ 0 ] ) { return TRUE; } pConvert->Rect.left = GetDlgItemInt( hWnd, IDC_CONVERT_LEFT , NULL, FALSE ); pConvert->Rect.top = GetDlgItemInt( hWnd, IDC_CONVERT_TOP , NULL, FALSE ); pConvert->Rect.right = GetDlgItemInt( hWnd, IDC_CONVERT_RIGHT , NULL, FALSE ); pConvert->Rect.bottom = GetDlgItemInt( hWnd, IDC_CONVERT_BOTTOM, NULL, FALSE ); pConvert->uDPI = GetDlgItemInt( hWnd, IDC_CONVERT_DPI, NULL, FALSE ); /* ConvertData contains all the information needed */ if( TRUE == pConvert->bEMF ) { hEnhMetaFile = L_VecConvertToEMF( pConvert->hDC, pConvert->pData->pVector, &pConvert->Rect, pConvert->uDPI ); if( NULL != hEnhMetaFile ) { /* Successful conversion */ hEnhMetaFile2 = CopyEnhMetaFile( hEnhMetaFile, pConvert->szFileName ); } } else { hMetaFile = L_VecConvertToWMF( pConvert->hDC, pConvert->pData->pVector, &pConvert->Rect, pConvert->uDPI ); if( NULL != hMetaFile ) { /* Successful conversion */ ZeroMemory( &OsVersionInfo, sizeof(OSVERSIONINFO) ); OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx( &OsVersionInfo ); if( VER_PLATFORM_WIN32_WINDOWS == OsVersionInfo.dwPlatformId ) { L_TCHAR szShortPath[MAX_PATH]; L_INT dRet; L_INT nFileHandle; nFileHandle = _topen( pConvert->szFileName, O_BINARY | O_RDWR | O_CREAT | O_TRUNC,S_IWRITE ); GetShortPathName( pConvert->szFileName, szShortPath, MAX_PATH - 1 ); _close( nFileHandle ); dRet = _tremove( pConvert->szFileName ); hMetaFile2 = CopyMetaFile( hMetaFile, szShortPath ); } else { hMetaFile2 = CopyMetaFile( hMetaFile, pConvert->szFileName ); } } } if ( ((NULL != hEnhMetaFile) && (NULL == hEnhMetaFile2)) || ((NULL != hMetaFile) && (NULL == hMetaFile2)) ) MessageBoxA( hWnd, "Incorrect file path ", "Vector", MB_OK | MB_ICONEXCLAMATION ); else EndDialog( hWnd, SUCCESS ); return TRUE; case IDCANCEL: EndDialog( hWnd, FAILURE ); return TRUE; case IDC_CONVERT_BROWSE: ZeroMemory( &SaveFileName, sizeof( OPENFILENAME ) ); ZeroMemory( szFileName, sizeof( szFileName ) ); SaveFileName.lStructSize = sizeof( OPENFILENAME ); SaveFileName.hwndOwner = g_hWndClient; SaveFileName.hInstance = NULL; SaveFileName.lpstrFilter = ( pConvert->bEMF ? TEXT("Enhanced Meta files\0*.EMF\0") : TEXT("Window Meta Files\0*.WMF\0") ); SaveFileName.lpstrCustomFilter = NULL; SaveFileName.nMaxCustFilter = 0; SaveFileName.nFilterIndex = 0; SaveFileName.lpstrFile = szFileName; SaveFileName.nMaxFile = sizeof( szFileName )/sizeof(L_TCHAR); SaveFileName.lpstrFileTitle = NULL; SaveFileName.nMaxFileTitle = 0; SaveFileName.lpstrInitialDir = NULL; SaveFileName.lpstrTitle = TEXT("Save metafile"); SaveFileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; SaveFileName.nFileOffset = 0; SaveFileName.nFileExtension = 0; SaveFileName.lpstrDefExt = ( pConvert->bEMF ? TEXT("EMF") : TEXT("WMF") ); SaveFileName.lCustData = 0L; SaveFileName.lpfnHook = NULL; SaveFileName.lpTemplateName = NULL; if( GetSaveFileName( &SaveFileName ) ) { SetDlgItemText( hWnd, IDC_CONVERT_PATH, szFileName ); } return TRUE; } } return FALSE; } /*---------------------------------------------------------------------------- | | CompareObjects | ---------------------------------------------------------------------------*/ static L_BOOL CompareObjects ( L_CHAR *pObjDesc1, L_CHAR *pObjDesc2, L_INT nType ) { L_BOOL bIsDifferent = FALSE; pVECTORPOLYLINE pVectorPolyLines[2]; pVECTORPOLYBEZIER pVectorPolyBeziers[2]; pVECTORPOLYGON pVectorPolygons[2]; pVECTORPOLYDRAW pVectorPolyDraws[2]; pVECTORRASTER pVectorRasters[2]; pVECTORVERTEX pVectorVertices[2]; pVECTORLINE pVectorLines[2]; pVECTORRECTANGLE pVectorRectangles[2]; pVECTORELLIPSE pVectorEllipses[2]; pVECTORCIRCLE pVectorCircles[2]; pVECTORARC pVectorArcs[2]; pVECTORELLIPTICALARC pVectorElliptialArcs[2]; pVECTORPIE pVectorPies[2]; pVECTORCHORD pVectorChords[2]; pVECTORCLONE pVectorClones[2]; pVECTORTEXT pVectorTexts[2]; pVECTORSPLINE pVectorSpline[2]; pVECTORHPOLYBEZIER pVectorHPolyBezier[2]; L_INT aSum[2]; switch ( nType ) { case VECTOR_POLYLINE: pVectorPolyLines[0] = (pVECTORPOLYLINE) pObjDesc1; pVectorPolyLines[1] = (pVECTORPOLYLINE) pObjDesc2; if ( 0 != memcmp( &pVectorPolyLines[0]->Object, &pVectorPolyLines[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorPolyLines[0]->Pen, &pVectorPolyLines[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != ComparePoints( pVectorPolyLines[0]->Point, pVectorPolyLines[0]->nPointCount, pVectorPolyLines[1]->Point, pVectorPolyLines[1]->nPointCount ) ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_POLYBEZIER: pVectorPolyBeziers[0] = (pVECTORPOLYBEZIER) pObjDesc1; pVectorPolyBeziers[1] = (pVECTORPOLYBEZIER) pObjDesc2; if ( 0 != memcmp( &pVectorPolyBeziers[0]->Object, &pVectorPolyBeziers[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorPolyBeziers[0]->Pen, &pVectorPolyBeziers[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != ComparePoints( pVectorPolyBeziers[0]->Point, pVectorPolyBeziers[0]->nPointCount, pVectorPolyBeziers[1]->Point, pVectorPolyBeziers[1]->nPointCount ) ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_POLYGON: pVectorPolygons[0] = (pVECTORPOLYGON) pObjDesc1; pVectorPolygons[1] = (pVECTORPOLYGON) pObjDesc2; if ( 0 != memcmp( &pVectorPolygons[0]->Object, &pVectorPolygons[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorPolygons[0]->Pen, &pVectorPolygons[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != CompareBrush( &pVectorPolygons[0]->Brush, &pVectorPolygons[1]->Brush ) ) bIsDifferent = TRUE; else if ( 0 != ComparePoints( pVectorPolygons[0]->Point, pVectorPolygons[0]->nPointCount, pVectorPolygons[1]->Point, pVectorPolygons[1]->nPointCount ) ) bIsDifferent = TRUE; else if ( pVectorPolygons[0]->nPolyFillMode != pVectorPolygons[1]->nPolyFillMode ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_POLYDRAW: pVectorPolyDraws[0] = (pVECTORPOLYDRAW) pObjDesc1; pVectorPolyDraws[1] = (pVECTORPOLYDRAW) pObjDesc2; if ( 0 != memcmp( &pVectorPolyDraws[0]->Object, &pVectorPolyDraws[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorPolyDraws[0]->Pen, &pVectorPolyDraws[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != CompareBrush( &pVectorPolyDraws[0]->Brush, &pVectorPolyDraws[1]->Brush ) ) bIsDifferent = TRUE; else if ( 0 != ComparePoints( pVectorPolyDraws[0]->Point, pVectorPolyDraws[0]->nPointCount, pVectorPolyDraws[1]->Point, pVectorPolyDraws[1]->nPointCount ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( pVectorPolyDraws[0]->pbyType, pVectorPolyDraws[1]->pbyType, sizeof(pVectorPolyDraws[0]->pbyType[0]) * pVectorPolyDraws[0]->nPointCount ) ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_RASTER: pVectorRasters[0] = (pVECTORRASTER) pObjDesc1; pVectorRasters[1] = (pVECTORRASTER) pObjDesc2; if ( 0 != memcmp( &pVectorRasters[0]->Object, &pVectorRasters[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePoints( pVectorRasters[0]->Point, 2, pVectorRasters[1]->Point, 2 ) ) bIsDifferent = TRUE; else if ( pVectorRasters[0]->Bitmap.nSize != pVectorRasters[1]->Bitmap.nSize ) bIsDifferent = TRUE; else if ( 0 != CompareBitmapsData( &pVectorRasters[0]->Bitmap.Bitmap , &pVectorRasters[1]->Bitmap.Bitmap ) ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_VERTEX: pVectorVertices[0] = (pVECTORVERTEX) pObjDesc1; pVectorVertices[1] = (pVECTORVERTEX) pObjDesc2; if ( 0 != memcmp( &pVectorVertices[0]->Object, &pVectorVertices[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorVertices[0]->Pen, &pVectorVertices[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorVertices[0]->Point, &pVectorVertices[1]->Point, sizeof(VECTORPOINT) ) ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_LINE: pVectorLines[0] = (pVECTORLINE) pObjDesc1; pVectorLines[1] = (pVECTORLINE) pObjDesc2; if ( 0 != memcmp( &pVectorLines[0]->Object, &pVectorLines[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorLines[0]->Pen, &pVectorLines[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != ComparePoints( pVectorLines[0]->Point, 2, pVectorLines[1]->Point, 2 ) ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_RECTANGLE: pVectorRectangles[0] = (pVECTORRECTANGLE) pObjDesc1; pVectorRectangles[1] = (pVECTORRECTANGLE) pObjDesc2; if ( 0 != memcmp( &pVectorRectangles[0]->Object, &pVectorRectangles[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorRectangles[0]->Pen, &pVectorRectangles[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != CompareBrush( &pVectorRectangles[0]->Brush, &pVectorRectangles[1]->Brush ) ) bIsDifferent = TRUE; else if ( 0 != ComparePoints( pVectorRectangles[0]->Point, 2, pVectorRectangles[1]->Point, 2 ) ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_ELLIPSE: pVectorEllipses[0] = (pVECTORELLIPSE) pObjDesc1; pVectorEllipses[1] = (pVECTORELLIPSE) pObjDesc2; if ( 0 != memcmp( &pVectorEllipses[0]->Object, &pVectorEllipses[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorEllipses[0]->Pen, &pVectorEllipses[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != CompareBrush( &pVectorEllipses[0]->Brush, &pVectorEllipses[1]->Brush ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorEllipses[0]->Point, &pVectorEllipses[1]->Point, sizeof(VECTORPOINT) ) ) bIsDifferent = TRUE; else if ( pVectorEllipses[0]->xRadius != pVectorEllipses[1]->xRadius ) bIsDifferent = TRUE; else if ( pVectorEllipses[0]->yRadius != pVectorEllipses[1]->yRadius ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_CIRCLE: pVectorCircles[0] = (pVECTORCIRCLE) pObjDesc1; pVectorCircles[1] = (pVECTORCIRCLE) pObjDesc2; if ( 0 != memcmp( &pVectorCircles[0]->Object, &pVectorCircles[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorCircles[0]->Pen, &pVectorCircles[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != CompareBrush( &pVectorCircles[0]->Brush, &pVectorCircles[1]->Brush ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorCircles[0]->Point, &pVectorCircles[1]->Point, sizeof(VECTORPOINT) ) ) bIsDifferent = TRUE; else if ( pVectorCircles[0]->Radius != pVectorCircles[1]->Radius ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_ARC: pVectorArcs[0] = (pVECTORARC) pObjDesc1; pVectorArcs[1] = (pVECTORARC) pObjDesc2; if ( 0 != memcmp( &pVectorArcs[0]->Object, &pVectorArcs[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorArcs[0]->Pen, &pVectorArcs[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorArcs[0]->Point, &pVectorArcs[1]->Point, sizeof(VECTORPOINT) ) ) bIsDifferent = TRUE; else if ( pVectorArcs[0]->Radius != pVectorArcs[1]->Radius ) bIsDifferent = TRUE; else if ( pVectorArcs[0]->StartAngle != pVectorArcs[1]->StartAngle ) bIsDifferent = TRUE; else if ( pVectorArcs[0]->SweepAngle != pVectorArcs[1]->SweepAngle ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_ELLIPTICALARC: pVectorElliptialArcs[0] = (pVECTORELLIPTICALARC) pObjDesc1; pVectorElliptialArcs[1] = (pVECTORELLIPTICALARC) pObjDesc2; if ( 0 != memcmp( &pVectorElliptialArcs[0]->Object, &pVectorElliptialArcs[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorElliptialArcs[0]->Pen, &pVectorElliptialArcs[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorElliptialArcs[0]->Point, &pVectorElliptialArcs[1]->Point, sizeof(VECTORPOINT) ) ) bIsDifferent = TRUE; else if ( pVectorElliptialArcs[0]->xRadius != pVectorElliptialArcs[1]->xRadius ) bIsDifferent = TRUE; else if ( pVectorElliptialArcs[0]->yRadius != pVectorElliptialArcs[1]->yRadius ) bIsDifferent = TRUE; else if ( pVectorElliptialArcs[0]->StartAngle != pVectorElliptialArcs[1]->StartAngle ) bIsDifferent = TRUE; else if ( pVectorElliptialArcs[0]->SweepAngle != pVectorElliptialArcs[1]->SweepAngle ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_PIE: pVectorPies[0] = (pVECTORPIE) pObjDesc1; pVectorPies[1] = (pVECTORPIE) pObjDesc2; if ( 0 != memcmp( &pVectorPies[0]->Object, &pVectorPies[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorPies[0]->Pen, &pVectorPies[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != CompareBrush( &pVectorPies[0]->Brush, &pVectorPies[1]->Brush ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorPies[0]->Point, &pVectorPies[1]->Point, sizeof(VECTORPOINT) ) ) bIsDifferent = TRUE; else if ( pVectorPies[0]->Radius != pVectorPies[1]->Radius ) bIsDifferent = TRUE; else if ( pVectorPies[0]->StartAngle != pVectorPies[1]->StartAngle ) bIsDifferent = TRUE; else if ( pVectorPies[0]->SweepAngle != pVectorPies[1]->SweepAngle ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_CHORD: pVectorChords[0] = (pVECTORCHORD) pObjDesc1; pVectorChords[1] = (pVECTORCHORD) pObjDesc2; if ( 0 != memcmp( &pVectorChords[0]->Object, &pVectorChords[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorChords[0]->Pen, &pVectorChords[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != CompareBrush( &pVectorChords[0]->Brush, &pVectorChords[1]->Brush ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorChords[0]->Point, &pVectorChords[1]->Point, sizeof(VECTORPOINT) ) ) bIsDifferent = TRUE; else if ( pVectorChords[0]->Radius != pVectorChords[1]->Radius ) bIsDifferent = TRUE; else if ( pVectorChords[0]->StartAngle != pVectorChords[1]->StartAngle ) bIsDifferent = TRUE; else if ( pVectorChords[0]->SweepAngle != pVectorChords[1]->SweepAngle ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_CLONE: pVectorClones[0] = (pVECTORCLONE) pObjDesc1; pVectorClones[1] = (pVECTORCLONE) pObjDesc2; if ( 0 != memcmp( &pVectorClones[0]->Object, &pVectorClones[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorClones[0]->Pen, &pVectorClones[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != CompareBrush( &pVectorClones[0]->Brush, &pVectorClones[1]->Brush ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorClones[0]->Point, &pVectorClones[1]->Point, sizeof(VECTORPOINT) ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorClones[0]->Scale, &pVectorClones[1]->Scale, sizeof(VECTORPOINT) ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorClones[0]->Rotation, &pVectorClones[1]->Rotation, sizeof(VECTORPOINT) ) ) bIsDifferent = TRUE; else if ( pVectorClones[0]->dwFlags != pVectorClones[1]->dwFlags ) bIsDifferent = TRUE; else if ( pVectorClones[0]->Group.nId != pVectorClones[0]->Group.nId ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_TEXT: pVectorTexts[0] = (pVECTORTEXT) pObjDesc1; pVectorTexts[1] = (pVECTORTEXT) pObjDesc2; if ( 0 != memcmp( &pVectorTexts[0]->Object, &pVectorTexts[1]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorTexts[0]->Pen, &pVectorTexts[1]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != CompareBrush( &pVectorTexts[0]->Brush, &pVectorTexts[1]->Brush ) ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorTexts[0]->Point, &pVectorTexts[1]->Point, sizeof(VECTORPOINT) ) ) bIsDifferent = TRUE; else if ( 0 != lstrcmp( pVectorTexts[0]->pszText, pVectorTexts[1]->pszText ) ) bIsDifferent = TRUE; else if ( pVectorTexts[0]->dwFlags != pVectorTexts[1]->dwFlags ) bIsDifferent = TRUE; else if ( pVectorTexts[0]->CharHeight != pVectorTexts[1]->CharHeight ) bIsDifferent = TRUE; else if ( pVectorTexts[0]->CharWidth != pVectorTexts[1]->CharWidth ) bIsDifferent = TRUE; else if ( 0 != memcmp( &pVectorTexts[0]->Font, &pVectorTexts[1]->Font, sizeof(VECTORFONT) ) ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_SPLINE: pVectorSpline[ 0 ] = (pVECTORSPLINE) pObjDesc1; pVectorSpline[ 1 ] = (pVECTORSPLINE) pObjDesc2; if ( 0 != memcmp( &pVectorSpline[ 0 ]->Object, &pVectorSpline[ 1 ]->Object, sizeof( VECTOROBJECT ) ) ) bIsDifferent = TRUE; else if ( pVectorSpline[ 0 ]->dwFlags != pVectorSpline[ 1 ]->dwFlags ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorSpline[ 0 ]->Pen, &pVectorSpline[ 1 ]->Pen ) ) bIsDifferent = TRUE; else if ( 0 != ComparePoints( pVectorSpline[ 0 ]->Point, pVectorSpline[ 0 ]->nPointCount, pVectorSpline[1]->Point, pVectorSpline[ 1 ]->nPointCount ) ) bIsDifferent = TRUE; else bIsDifferent = FALSE; break; case VECTOR_HPOLYBEZIER: pVectorHPolyBezier[0] = (pVECTORHPOLYBEZIER) pObjDesc1; pVectorHPolyBezier[1] = (pVECTORHPOLYBEZIER) pObjDesc2; if ( 0 != memcmp( &pVectorHPolyBezier[ 0 ]->Object, &pVectorHPolyBezier[ 1 ]->Object, sizeof(VECTOROBJECT) ) ) bIsDifferent = TRUE; else if ( 0 != ComparePen( &pVectorHPolyBezier[ 0 ]->Pen, &pVectorHPolyBezier[ 1 ]->Pen ) ) bIsDifferent = TRUE; else if ( pVectorHPolyBezier[ 0 ]->nSecCount != pVectorHPolyBezier[ 1 ]->nSecCount ) bIsDifferent = TRUE; else if ( 0 != memcmp( pVectorHPolyBezier[ 0 ]->puDegree, pVectorHPolyBezier[ 1 ]->puDegree, pVectorHPolyBezier[ 0 ]->nSecCount * sizeof( L_INT ) ) ) bIsDifferent = TRUE; if( !bIsDifferent ) { L_INT i,j; memset( &aSum, 1, sizeof( aSum ) ); for( j = 0 ; j < 2 ; j ++ ) { for( i = 0; i < pVectorHPolyBezier[ 0 ]->nSecCount ; i ++ ) { aSum[ j ] += pVectorHPolyBezier[ 0 ]->puDegree[ i ]; } } if ( 0 != ComparePoints( pVectorHPolyBezier[ 0 ]->Point, aSum[ 0 ] , pVectorHPolyBezier[ 1 ]->Point, aSum[ 1 ] ) ) bIsDifferent = TRUE; else bIsDifferent = FALSE; } break; default: bIsDifferent = FALSE; } return bIsDifferent; } /*---------------------------------------------------------------------------- | | CompareBrush | ---------------------------------------------------------------------------*/ static L_INT CompareBrush ( pVECTORBRUSH pVectorBrush1, pVECTORBRUSH pVectorBrush2 ) { return memcmp( pVectorBrush1, pVectorBrush2, sizeof(VECTORBRUSH) ); } /*---------------------------------------------------------------------------- | | ComparePen | ---------------------------------------------------------------------------*/ static L_INT ComparePen ( pVECTORPEN pVectorPen1, pVECTORPEN pVectorPen2 ) { L_INT nCompare; nCompare = memcmp( pVectorPen1, pVectorPen2, sizeof(VECTORPEN) ); return nCompare; } /*---------------------------------------------------------------------------- | | ComparePoints | ---------------------------------------------------------------------------*/ static L_INT ComparePoints ( pVECTORPOINT pPoints1, L_INT nPoints1Count, pVECTORPOINT pPoints2, L_INT nPoints2Count ) { if ( nPoints1Count != nPoints2Count ) return 1; return memcmp( pPoints1, pPoints2, nPoints1Count * sizeof(VECTORPOINT) ); } /*---------------------------------------------------------------------------- | | CompareBitmapsData | ---------------------------------------------------------------------------*/ static L_INT CompareBitmapsData ( pBITMAPHANDLE pBitmap1, pBITMAPHANDLE pBitmap2 ) { L_UCHAR L_FAR *pBuffer1 = NULL; L_UCHAR L_FAR *pBuffer2 = NULL; L_INT i; if ( 0 != memcmp( pBitmap1, pBitmap1, sizeof(BITMAPHANDLE) ) ) return 1; pBuffer1 = malloc( sizeof(L_UCHAR) * pBitmap1->BytesPerLine ); if ( NULL == pBuffer1 ) return ERROR_NOT_ENOUGH_MEMORY; pBuffer2 = malloc( sizeof(L_UCHAR) * pBitmap2->BytesPerLine ); if ( NULL == pBuffer2 ) { free( pBuffer1 ); pBuffer1 = NULL; return ERROR_NOT_ENOUGH_MEMORY; } for( i = 0; i < BITMAPHEIGHT(pBitmap1); i++ ) { L_GetBitmapRow( pBitmap1, pBuffer1, i, pBitmap1->BytesPerLine ); L_GetBitmapRow( pBitmap2, pBuffer2, i, pBitmap2->BytesPerLine ); if ( 0 != memcmp( pBuffer1, pBuffer2, sizeof(L_UCHAR) * pBitmap1->BytesPerLine ) ) return 1; } if ( NULL != pBuffer1 ) { free( pBuffer1 ); pBuffer1 = NULL; } if ( NULL != pBuffer2 ) { free( pBuffer2 ); pBuffer2 = NULL; } return 0; } /*---------------------------------------------------------------------------- | | PushToUndoBuffer | ---------------------------------------------------------------------------*/ static L_INT PushToUndoBuffer ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_TCHAR **szTemp = NULL; L_INT nRet = SUCCESS; L_TCHAR szBuffer[L_MAXPATH]; pData->UndoData.nNumberOfActions++; szTemp = (L_TCHAR**) realloc( pData->UndoData.szTempFilesNames, sizeof(L_TCHAR*) * pData->UndoData.nNumberOfActions ); if ( NULL == szTemp ) { pData->UndoData.nNumberOfActions--; return ERROR_NOT_ENOUGH_MEMORY; } pData->UndoData.szTempFilesNames = szTemp; #ifdef _UNICODE pData->UndoData.szTempFilesNames[pData->UndoData.nNumberOfActions -1] = _wtempnam( TEXT("c:\\tmp"), TEXT("VecDemo") ); #else pData->UndoData.szTempFilesNames[pData->UndoData.nNumberOfActions -1] = _tempnam ( "c:\\tmp", "VecDemo" ); #endif if ( NULL == pData->UndoData.szTempFilesNames[pData->UndoData.nNumberOfActions -1] ) { pData->UndoData.nNumberOfActions--; pData->UndoData.szTempFilesNames = (L_TCHAR**) realloc( pData->UndoData.szTempFilesNames, sizeof(L_TCHAR*) * pData->UndoData.nNumberOfActions ); return ERROR_NOT_ENOUGH_MEMORY; } if( TRUE == pData->ChildEx.bValidTooltipObj ) { nRet = L_VecHideObjectTooltip( pData->pVector, &pData->ChildEx.TooltipObj ); } if ( NULL != pData->pVector ) { nRet = L_VecSaveFile( pData->UndoData.szTempFilesNames[pData->UndoData.nNumberOfActions -1], pData->pVector, FILE_VECTOR_DUMP, NULL ); } if( TRUE == pData->ChildEx.bValidTooltipObj ) { nRet = L_VecShowObjectTooltip( pData->pVector, &pData->ChildEx.TooltipObj, &pData->ChildEx.TooltipDesc ); InvalidateRect( hWnd, NULL, FALSE ); } if ( ! pData->UndoData.bIsDirty ) { GetWindowText( hWnd, szBuffer, sizeof(szBuffer) ); lstrcat( szBuffer, TEXT("*") ); SetWindowText( hWnd, szBuffer ); } pData->UndoData.bIsDirty = TRUE; return nRet; } /*---------------------------------------------------------------------------- | | PopFromUndoBuffer | ---------------------------------------------------------------------------*/ static L_INT PopFromUndoBuffer ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT nRet; L_TCHAR szBuffer[L_MAXPATH]; L_UINT uSize = 0; if ( 0 == pData->UndoData.nNumberOfActions ) return SUCCESS; nRet = L_VecFree( pData->pVector ); if ( SUCCESS != nRet ) return nRet; nRet = L_VecLoadFile( pData->UndoData.szTempFilesNames[pData->UndoData.nNumberOfActions -1], pData->pVector, NULL, NULL ); if ( SUCCESS != nRet ) return nRet; DeleteFile( pData->UndoData.szTempFilesNames[pData->UndoData.nNumberOfActions -1] ); free( pData->UndoData.szTempFilesNames[pData->UndoData.nNumberOfActions -1] ); pData->UndoData.nNumberOfActions--; if ( 0 == pData->UndoData.nNumberOfActions ) pData->UndoData.bIsDirty = FALSE; if ( ! pData->UndoData.bIsDirty ) { GetWindowText( hWnd, szBuffer, sizeof(szBuffer) ); uSize = lstrlen( szBuffer ); szBuffer[uSize - 1] = '\0'; SetWindowText( hWnd, szBuffer ); } pData->UndoData.szTempFilesNames = (L_TCHAR**) realloc( pData->UndoData.szTempFilesNames, sizeof(L_TCHAR*) * pData->UndoData.nNumberOfActions ); return SUCCESS; } /*---------------------------------------------------------------------------- | | CleanUndoData | ---------------------------------------------------------------------------*/ static L_INT CleanUndoData ( HWND hWnd ) { LPCHILDDATA pData = GETCHILDDATA( hWnd ); L_INT i; for ( i = 0; i < pData->UndoData.nNumberOfActions; i++ ) { DeleteFile( pData->UndoData.szTempFilesNames[i] ); free( pData->UndoData.szTempFilesNames[i] ); pData->UndoData.szTempFilesNames[i] = NULL; } free( pData->UndoData.szTempFilesNames ); pData->UndoData.szTempFilesNames = NULL; return SUCCESS; } /*---------------------------------------------------------------------------- | | myFontMapper | ---------------------------------------------------------------------------*/ L_INT WINAPI myFontMapper( pVECTORHANDLE pVector, LPLOGFONT pLogFont, L_VOID* pUserData ) { UNREFERENCED_PARAMETER( pVector ); UNREFERENCED_PARAMETER( pLogFont ); UNREFERENCED_PARAMETER( pUserData ); /* pUserData points to "Arial" .. copy it to pLogFont->lfFaceName to force the toolkit to render all fonts as Arial */ /* #ifdef _UNICODE wcscpy( pLogFont->lfFaceName, (L_TCHAR *)pUserData ); #else strcpy( pLogFont->lfFaceName, (L_CHAR *)pUserData ); #endif */ return SUCCESS; } /*---------------------------------------------------------------------------- | | CreateDefaultLayer | ---------------------------------------------------------------------------*/ static L_INT CreateDefaultLayer ( pVECTORHANDLE pVector ) { VECTORLAYERDESC LayerDesc; VECTORLAYER Layer; L_INT nRet; ZeroMemory( &LayerDesc, sizeof( LayerDesc ) ); LayerDesc.nSize = sizeof( LayerDesc ); lstrcpy( LayerDesc.szName, TEXT("0") ); LayerDesc.bVisible = TRUE; nRet = L_VecAddLayer( pVector, &LayerDesc, &Layer, 0L ); if( SUCCESS == nRet ) { nRet = L_VecSetActiveLayer( pVector, &Layer ); } return( nRet ); } /* EOF ----------------------------------------------------------------------*/