home *** CD-ROM | disk | FTP | other *** search
- // GptMeta.cpp - Windows Metafile Playing
- // copyright 1992 Pittsburgh Supercomputing Center
- #include "gpt.h"
-
- char WMetaWindow::szClass[] = "gptWMeta";
- char WMetaWindow::szMenu[] = "gptMenuWMeta";
- HMENU WMetaWindow::hMenu = NULL;
- HMENU WMetaWindow::hMenuWindow = NULL;
- // Metafile Enumeration Callback Function
- int FAR PASCAL WMetaWindow::MetaEnum(HDC hDC, LPHANDLETABLE lpHTable,
- LPMETARECORD lpMFR, int nObj,BYTE FAR * lpClientData)
- {
- int *extent = (int *)lpClientData;
-
- int foo;
- foo = 1; // Keep going until find first Rectangle
-
- if ( lpMFR->rdFunction == META_RECTANGLE && !extent[2] ) // get extent info from bgrnd rect
- {
- int bot = lpMFR->rdParm[0];
- int right = lpMFR->rdParm[1];
- extent[0] = right;
- extent[1] = bot;
- extent[2] = 1; // so only get first rectangle
- //foo = 0; ... if stop craps up everything!!!!!
- }
- return foo;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- // ******************* WMetaWindow Declarations *****************
- void WMetaWindow::DoCaption ( LPSTR mesg)
- {
- char szCaption [80] ;
-
- wsprintf (szCaption, "%s - %s", (LPSTR) mesg,
- (LPSTR) (FObj->GetFileName() )) ;
-
- SetWindowText (hWndThis, szCaption) ;
- }
-
-
-
-
- // *** WMetaWindow::WndProc
- long WMetaWindow::WndProc(HWND hWnd, WORD iMessage, WORD wParam,
- LONG lParam )
- {
- char tmp[256];
- this->iMessage = iMessage;
- this->wParam = wParam;
- this->lParam = lParam;
- switch (iMessage)
- {
- case WM_CREATE:
- hWndThis = hWnd;
- SetExtents();
- SBars = new Scroller(this, MetaX, MetaY );
- SBars->SetXRatio((float)MetaX/(float)DrawRect.right);
- SBars->SetYRatio((float)MetaY/(float)DrawRect.bottom);
-
- DoCaption("Metafile Paint");
- return 0;
-
-
- case WM_INITMENUPOPUP:
- return 0;
-
-
- case WM_PAINT:
- Paint();
- //DrawMenuBar(Appl::hWndFrame);
- return 0;
-
- case WM_SIZE:
- Size();
- break;
-
- case WM_VSCROLL:
- case WM_HSCROLL:
- SBars->Scroll();
- break;
-
- case WM_COMMAND:
- return 0;
-
- case WM_MDIACTIVATE:
- if (wParam == TRUE) Activate();
- else DeActivate();
- return 0;
-
- case WM_QUERYENDSESSION:
- case WM_CLOSE:
- SendMessage (GetParent (hWnd), WM_MDIRESTORE, hWnd, 0L) ;
- if (IDOK != MessageBox(hWnd,"OK to close window??","Metafile Close",
- MB_ICONQUESTION | MB_OKCANCEL)) return 0;
- break;
-
- case WM_NCDESTROY:
- delete this;
- break;
- }
- return DefMDIChildProc( hWnd, iMessage, wParam, lParam );
- }
-
-
-
- void WMetaWindow::Size()
- {
- LONG lSize = this->lParam;
- WORD wType = this->wParam;
- cxClient = LOWORD(lSize);
- cyClient = HIWORD(lSize);
- int LogicalX = (float)MetaX *((float)cxClient/DrawRect.right);
- int LogicalY = (float)MetaX *((float)cyClient/DrawRect.right);
- //if (SBars) SBars->NewSize(cxClient, cyClient);
- if (SBars) SBars->NewSize(LogicalX, LogicalY);
- }
-
-
- void WMetaWindow::Paint( void )
- {
- RECT rect;
- PAINTSTRUCT ps;
-
- HDC hdc = BeginPaint(hWndThis, &ps);
- if (!hMemDC)
- {
- SetMapMode(hdc, MM_ANISOTROPIC);
- SetWindowExt(hdc,MetaX, MetaY);
- SetViewportExt(hdc, DrawRect.right, DrawRect.bottom);
-
- SetWindowOrg(hdc,+SBars->getnHscrollPos(),+SBars->getnVscrollPos());
-
-
- //if (!hmf) { EndPaint(hWndThis, &ps); return;}
- BOOL metaStat = PlayMetaFile(hdc, hmf);
- EndPaint(hWndThis,&ps);
- if (!metaStat) return;
- hdc = GetDC(hWndThis);
- //hCompBit = CreateCompatibleBitmap(hdc,DrawRect.right, DrawRect.bottom);
- hCompBit = CreateCompatibleBitmap(hdc,MetaX, MetaY);
- hMemDC = CreateCompatibleDC(hdc);
- hOldBit = SelectObject( hMemDC, hCompBit);
- SetMapMode(hMemDC, MM_ANISOTROPIC);
-
- SetWindowExt(hMemDC,MetaX, MetaY);
- //SetViewportExt(hMemDC, DrawRect.right, DrawRect.bottom);
- SetViewportExt(hMemDC, MetaX, MetaY); // So clip OK
- PlayMetaFile(hMemDC,hmf); // Play metafile in memory
- ReleaseDC(hWndThis, hdc);
- return;
- }
- else
- {
- //SetMapMode(hdc, MM_TEXT);
- SetMapMode(hdc, MM_ANISOTROPIC);
-
- SetWindowExt(hdc,MetaX, MetaY);
- SetViewportExt(hdc, DrawRect.right, DrawRect.bottom);
- int XSrc = +SBars->getnHscrollPos();
- int YSrc = +SBars->getnVscrollPos();
- SetWindowOrg(hdc,XSrc,YSrc);
- BOOL moo =
- // StretchBlt( hdc, 0, 0,DrawRect.right-XSrc, DrawRect.bottom-YSrc,
- /// hMemDC, XSrc, YSrc, MetaX-XSrc,MetaY-YSrc,SRCCOPY);
- StretchBlt( hdc, XSrc, YSrc,MetaX -XSrc, MetaY -YSrc,
- hMemDC, XSrc, YSrc, MetaX-XSrc,MetaY-YSrc,SRCCOPY);
- EndPaint(hWndThis, &ps);
- //MakeBitmapMeta(hWnd, rect, sbars); OBSOLETE CODE
- return;
- }
- //****************** */
- }
-
- void WMetaWindow::SetExtents()
- {
- char filename[150];
- MetaX = DrawRect.right;
- MetaY = DrawRect.bottom;
-
- strcpy(filename, FObj->GetFileName() );
- hmf = GetMetaFile( filename);
- if (hmf)
- {
- FARPROC lpEnumFunc;
- lpEnumFunc = MakeProcInstance( (FARPROC) WMetaWindow::MetaEnum,
- Appl::hInstance );
- HDC hdcX = GetDC(hWndThis);
- int Extents[3];
- Extents[0] = MetaX;
- Extents[1] = MetaY;
- Extents[2] = 0; // a flag for enum proc
- BYTE FAR * lpClientData = (BYTE FAR *)Extents;
- //int nSavedDC = SaveDC(hdcX);
- EnumMetaFile(hdcX, hmf, lpEnumFunc, lpClientData) ;
- //RestoreDC(hdcX, nSavedDC);
- MetaX = Extents[0];
- MetaY = Extents[1];
- ReleaseDC(hWndThis, hdcX);
- FreeProcInstance( lpEnumFunc );
- //DeleteMetaFile(hmfX); // close old one
-
- } // MetaX = 1024/640; MetaY = 714/442;
- }
-
-
- // *** WMetaWindow constructor
- // Constructor
- WMetaWindow::WMetaWindow(FileObjectPt myfile )
- {
- MDICREATESTRUCT mdicreate;
- hCompBit = NULL;
- hMemDC = NULL;
- hOldBit = NULL;
-
- SBars = NULL;
- errors = 0;
- severe_error = FALSE;
- ErrMsg1 = NULL;
- ErrMsg2 = NULL;
- FObj = myfile;
- DrawRect.top = DrawRect.left = 0;
- DrawRect.right = GetSystemMetrics(SM_CXSCREEN);
- DrawRect.bottom = GetSystemMetrics(SM_CYSCREEN)
- - GetSystemMetrics(SM_CYCAPTION)
- - GetSystemMetrics(SM_CYMENU);
- // FObj->DialogFileInfo( );
- hmf = NULL; // never been painted
-
- mdicreate.szClass = szClass;
- mdicreate.szTitle = "Metafile" ;
- mdicreate.hOwner = Appl::hInstance ;
- mdicreate.x = CW_USEDEFAULT ;
- mdicreate.y = CW_USEDEFAULT ;
- mdicreate.cx = CW_USEDEFAULT ;
- mdicreate.cy = CW_USEDEFAULT ;
- mdicreate.style = WS_VSCROLL | WS_HSCROLL ;
- mdicreate.lParam = (LONG) this ;
-
- HWND hWndChild = SendMessage (Appl::hWndClient, WM_MDICREATE, 0,
- (LONG) (LPMDICREATESTRUCT) &mdicreate) ;
- if ( ! hWndChild ) exit( FALSE );
-
- }
-
- // WMetaWindow Destructor
- WMetaWindow::~WMetaWindow( void )
- {
- DeleteMetaFile(hmf);
- delete SBars;
- delete FObj; // also closes open file
-
- DeleteSz(ErrMsg1);
- DeleteSz(ErrMsg2);
- if (hMemDC)
- {
- SelectObject(hMemDC, hOldBit);
- DeleteDC(hMemDC);
- DeleteObject(hCompBit);
- }
-
- }
-
- void WMetaWindow::LoadMenu(HANDLE hInstance)
- {
- hMenu = ::LoadMenu( hInstance,szMenu);
- hMenuWindow =
- GetSubMenu( hMenu,WMETA_MENU_POS);
- }
-
- // *** WMetaWindow::Activate
- void WMetaWindow::Activate( void )
- {
- SendMessage(Appl::hWndClient, WM_MDISETMENU,0,
- MAKELONG( hMenu, hMenuWindow));
-
- DrawMenuBar(Appl::hWndFrame);
- }
-
- // *** WMetaWindow::DeActivate
- void WMetaWindow::DeActivate( void )
- {
- Appl::theFrame->InitMenu();
- DrawMenuBar(Appl::hWndFrame);
- }
-
- // *** WMetaWindow::Register - static window class register
- void WMetaWindow::Register( void )
- {
- WNDCLASS wndclass; // Structure used to register Windows class.
-
- wndclass.style = CS_HREDRAW | CS_VREDRAW;
- wndclass.lpfnWndProc = ::gptWndProc; // the global one
- wndclass.cbClsExtra = 0;
- // Reserve extra bytes for each instance of the window;
- // we will use these bytes to store a pointer to the C++
- // (WMetaWindow) object corresponding to the window.
- // the size of a 'this' pointer depends on the memory model.
- wndclass.cbWndExtra = sizeof( WMetaWindow * );
- wndclass.hInstance = Appl::hInstance;
- wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
- wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
- wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
- wndclass.lpszMenuName = "gptMenuWMeta";
- wndclass.lpszClassName = szClass;
-
- if ( ! RegisterClass( &wndclass ) ) exit( FALSE );
- }
-
-