home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////////
- //
- // svdoc.cpp : Implementation of the CSVViewerDoc class
- //
- /////////////////////////////////////////////////////////////////////////////
- //
- // (C) Copyright Black Diamond Consulting, Inc 1996. All rights reserved.
- //
- // You have a royalty-free right to use, modify, reproduce and
- // distribute the Sample Files (and/or any modified version) in
- // any way you find useful, provided that you agree that Black
- // Diamond Consulting has no warranty obligations or liability
- // for any Sample Application Files which are modified.
- //
- // Revision History:
- //
- /////////////////////////////////////////////////////////////////////////////
-
- #include "stdafx.h"
- #include <stdlib.h>
- #include "dib.h"
-
- #ifndef __SVVIEWER_H__
- #include "SVViewer.h"
- #endif
-
- #ifndef __SVVIEW_H__
- #include "SVView.h"
- #endif
-
- #ifndef __SVDOC_H__
- #include "SVDoc.h"
- #endif
-
- #ifndef __CASTRING_H__
- #include "CAString.h"
- #endif
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CSVViewerDoc
-
- IMPLEMENT_DYNCREATE(CSVViewerDoc, CDocument)
-
- BEGIN_MESSAGE_MAP(CSVViewerDoc, CDocument)
- //{{AFX_MSG_MAP(CSVViewerDoc)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSVViewerDoc construction/destruction
-
- CSVViewerDoc::CSVViewerDoc()
- {
- m_pISurround = NULL;
- m_pIStorage = NULL;
- }
-
- BOOL CSVViewerDoc::OnOpenDocument(LPCTSTR lpszPathName)
- {
- HRESULT hr;
- IStorage *pIStorage = NULL;
- IStream *pStream = NULL;
- BITMAPINFOHEADER *pDib = NULL;
- BYTE *pvBits = NULL;
- CAnyString fileName = lpszPathName;
- CAnyString storageName = CSVDOC_SURROUNDIMAGE;
-
- // free up the current surround video image
- DeleteContents();
- SetModifiedFlag( FALSE );
-
- TRY
- {
- // See if it's a compound file...
- hr = StgIsStorageFile( fileName );
- if( hr == STG_E_FILENOTFOUND )
- {
- AfxThrowFileException(0);
- }
- // ...it's not a compound file. See if it's a DIB...
- else if( hr != S_OK )
- {
- pDib = (BITMAPINFOHEADER*)GlobalAllocPtr( GHND, sizeof(BITMAPINFOHEADER) +
- 256*sizeof(RGBQUAD) );
- if( pDib == NULL )
- AfxThrowMemoryException();
-
- // See if it's a Dib we can treat as an Surround Video Image
- if( ReadDib( fileName, (BITMAPINFO*)pDib, &pvBits ) != DIB_OK )
- AfxThrowFileException(0);
-
- // Create a Surround from the Dib
- hr = PanoramicSurroundFromDIB( pDib,
- DibColors(pDib),
- pvBits,
- DibHeight(pDib) / 2,
- MAX_ARCSECONDS,
- &m_pISurround);
-
- if( FAILED(hr) ) AfxThrowFileException(0);
-
- return m_pISurround != NULL;
- }
-
- // NOTE WELL: The following section shows two ways of creating an ISurround from a file.
- // The first uses PanoramicSurroundFromFile() which just takes a file name.
- // The second uses PanoramicSurroundFromStream() which uses a stream.
-
- //#define USE_PanoramicSurroundFromFile // Comment this line out to use PanoramicSurroundFromStream()
-
- #ifdef USE_PanoramicSurroundFromFile
-
- // Get an ISurround using the highest color resolution we can based
- // on the display depth.
- HDC hdc = GetDC(NULL);
- hr = -1;
- if( GetDeviceCaps( hdc, BITSPIXEL ) > 8 )
- hr = PanoramicSurroundFromFile( fileName, 24, &m_pISurround );
- if( FAILED(hr) )
- hr = PanoramicSurroundFromFile( fileName, 8, &m_pISurround );
- ReleaseDC(NULL, hdc);
-
- #else
- // open the storage with the image filename
- hr = StgOpenStorage( fileName, NULL, STGM_READ|STGM_SHARE_EXCLUSIVE,
- 0, 0, &pIStorage);
-
- if( FAILED(hr) )
- AfxThrowFileException(0);
-
- hr = pIStorage->OpenStream ( storageName, NULL, STGM_READ|STGM_SHARE_EXCLUSIVE,
- 0, &pStream );
- if( FAILED(hr) )
- AfxThrowFileException(0);
-
- // Get an ISurround using the highest color resolution we can based
- // on the display depth.
- HDC hdc = GetDC(NULL);
- hr = -1;
- if( GetDeviceCaps( hdc, BITSPIXEL ) > 8 )
- hr = PanoramicSurroundFromStream( pStream, 24, &m_pISurround );
- if( FAILED(hr) )
- hr = PanoramicSurroundFromStream( pStream, 8, &m_pISurround );
- ReleaseDC(NULL, hdc);
-
- #endif // #ifdef USE_PanoramicSurroundFromFile
-
- if( FAILED(hr) )
- AfxThrowFileException(0);
- }
- CATCH_ALL(e)
- {
- if( pDib != NULL )
- GlobalFreePtr( pDib);
-
- if( pvBits != NULL )
- GlobalFreePtr( pvBits );
-
- AfxMessageBox( AFX_MSG_CANTREADFILE );
- }
- END_CATCH_ALL
-
- m_pIStorage = pIStorage;
-
- if (pStream)
- pStream->Release();
-
- return m_pISurround != NULL;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CSVViewerDoc diagnostics
-
- #ifdef _DEBUG
- void CSVViewerDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
-
- void CSVViewerDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
-
-
- CView* CSVViewerDoc::GetSVView(void)
- {
- // Loop through views looking for CSVViewerView,
- POSITION pos = GetFirstViewPosition();
- while(pos != NULL)
- {
- CView* pView = GetNextView(pos);
- if(pView->IsKindOf(RUNTIME_CLASS(CSVViewerView)))
- return pView;
- }
-
- return NULL;
- }
-
- void CSVViewerDoc::DeleteContents()
- {
- // Reset the CSVViewerView before attempting to reset myself
- CSVViewerView* pSVViewerView = (CSVViewerView*)GetSVView();
- if(NULL != pSVViewerView)
- pSVViewerView->Reset();
-
- // release our interfaces
- if (m_pISurround)
- {
- m_pISurround->Release();
- m_pISurround = NULL;
- }
-
- if (m_pIStorage)
- {
- m_pIStorage->Release();
- m_pIStorage = NULL;
- }
- }
-
-
-