home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////////
- //
- // svview.cpp : Implementation of the CSVViewerView 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 "windowsx.h"
- #include "resource.h"
-
- #ifndef _Surround_H_
- #include "Surround.h"
- #endif
-
- #ifndef __CSURVIEW_H__
- #include "CSurView.h"
- #endif
-
- #ifndef __SVVIEW_H__
- #include "SVView.h"
- #endif
-
- #ifndef __svDoc_H__
- #include "svDoc.h"
- #endif
-
- #ifndef __PSHOTSP_H__
- #include "psHotsp.h"
- #endif
-
- #ifndef __PPHSGEN_H__
- #include "ppHSGen.h"
- #endif
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CSVViewerView
-
- IMPLEMENT_DYNCREATE(CSVViewerView, CSurroundView)
-
- BEGIN_MESSAGE_MAP(CSVViewerView, CSurroundView)
- //{{AFX_MSG_MAP(CSVViewerView)
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_RBUTTONDOWN()
- ON_WM_RBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDBLCLK()
- ON_COMMAND( ID_EDIT_HOTSPOT, OnEditHotspot )
- ON_COMMAND( ID_EDIT_DELETE, OnDeleteHotspot )
- ON_COMMAND( ID_MODE_RUN, OnModeEdit )
- ON_COMMAND( ID_MODE_EDIT, OnModeEdit )
- ON_UPDATE_COMMAND_UI( ID_EDIT_HOTSPOT, OnUpdateCurrentHotspot )
- ON_UPDATE_COMMAND_UI( ID_EDIT_DELETE, OnUpdateCurrentHotspot )
- ON_UPDATE_COMMAND_UI( ID_MODE_RUN, OnUpdateModeRun )
- ON_UPDATE_COMMAND_UI( ID_MODE_EDIT, OnUpdateModeEdit )
- ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateSave)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSVViewerView construction/destruction
-
- CSVViewerView::CSVViewerView()
- {
- // No current hotspot
- m_currentHotspot = NULL;
- m_pHotspotDib = NULL;
- m_pAlteredDib = NULL;
-
- // Set default CRectTracker settings
- m_rectTracker.m_nStyle = CRectTracker::resizeInside;
- m_rectTracker.m_nHandleSize = ::GetSystemMetrics( SM_CYFRAME ) << 1;
-
- // Default to edit mode
- m_bEdit = TRUE;
- }
-
- CSVViewerView::~CSVViewerView()
- {
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CSVViewerView drawing
- void CSVViewerView::OnDraw(CDC* pDC)
- {
- // Base class will draw the image...
- CSurroundView::OnDraw(pDC);
-
- // Draw this scene's hotspots
- if( m_bEdit )
- DrawHotspots( pDC );
-
- // Draw a focus rect over the currently selected hotspot
- if( m_currentHotspot != NULL && m_bEdit )
- {
- m_rectTracker.m_nStyle = ( m_currentHotspot->IsLocked() )
- ? CRectTracker::hatchInside
- : CRectTracker::resizeInside;
- if( GetHotspotRect( &m_rectTracker.m_rect ) )
- m_rectTracker.Draw( pDC );
- }
- }
-
- // PtInHotspot() - Returns hotspot at current screen location
- CHotspot* CSVViewerView::PtInHotspot( CPoint point )
- {
- CHotspot *pHotspot;
- CHotspotList* pHotspots = ((CSVViewerDoc*)GetDocument())->GetHotspotList();
- CRect rect;
-
- int index = 0;
- while( ( pHotspot = (CHotspot *)pHotspots->GetByIndex( index++ ) ) != NULL )
- {
- if( GetHotspotRect( &rect, pHotspot ) && rect.PtInRect( point ) )
- return pHotspot;
- }
- return (CHotspot *)NULL;
- }
-
- // DrawHotspots() - Draw hotspots
- void CSVViewerView::DrawHotspots( CDC *pDC )
- {
- CHotspot* pHotspot;
- CHotspotList* pHotspots = ((CSVViewerDoc*)GetDocument())->GetHotspotList();
- RECT rect;
-
- int index = 0;
- while( ( pHotspot = (CHotspot *)pHotspots->GetByIndex( index++ ) ) != NULL )
- {
- if( GetHotspotRect( &rect, pHotspot ) )
- {
- if( pDC->RectVisible( &rect ) )
- pDC->DrawFocusRect( &rect );
- }
- }
- }
-
- // GetISuurround() - Returns the ISurround Interface pointer
- //
- // Note: This pure virtual member function of the CSurroundView class
- // is called from the base class to obtain the ISurround interface
- // pointer.
- //
- ISurround* CSVViewerView::GetISurround()
- {
- return ((CSVViewerDoc*)this->GetDocument())->GetISurround();
- }
-
- // GetHotspotRect() - return hotspot rect in client co-ordinates
- //
- // Accepts:
- // pRect Pointer to RECT in which client co-ordinates of the hotspot
- // will be returned
- // pHotspot Pointer to hotspot, if NULL, m_currentHotspot is assumed
- //
- // Returns:
- // TRUE pRect contains hotspot co-ordinates relative to client co-ordinates
- // FALSE pHotspot was invalid or there was no current view (program bug)
- //
- BOOL CSVViewerView::GetHotspotRect( RECT* pRect, CHotspot *pHotspot )
- {
- CHotspotList* hotspots = ((CSVViewerDoc*)GetDocument())->GetHotspotList();
-
- if( pHotspot == NULL )
- pHotspot = m_currentHotspot;
-
- if( !hotspots->IsValidEntry( pHotspot ) )
- return FALSE;
-
- // Calculate the viewport rect based on hotspot location and size
- return this->SphereToView( pHotspot->Location(), pHotspot->Size(), pRect ) == S_OK;
- }
-
- // SetHotspotRect() - Set Hotspot rect based on client rect
- //
- // Accepts:
- // pRect Pointer to RECT containing co-ordinates relative to client area
- // pHotspot Pointer to hotspot, if NULL, m_currentHotspot is assumed
- //
- // Returns:
- // TRUE Sets the hotspot size and location (in image co-ordinates)
- // FALSE pHotspot was invalid or there was no current view (program bug)
- //
- BOOL CSVViewerView::SetHotspotRect( RECT* pRect, CHotspot *pHotspot )
- {
- CHotspotList* hotspots = ((CSVViewerDoc*)GetDocument())->GetHotspotList();
-
- if( pHotspot == NULL )
- pHotspot = m_currentHotspot;
-
- if( !hotspots->IsValidEntry( pHotspot ) )
- return FALSE;
-
- // Set hotspot size and location based on client rect
- return this->ViewToSphere( pRect, pHotspot->Location(), pHotspot->Size() ) == S_OK;
- }
-
- // Alter() - Alter a Dib's bits so it will stand out
- //
- // This is pretty brain dead but works with bitmaps of any
- // bit depth and we just want to make it look different.
- //
- void CSVViewerView::Alter( PDIB pDib )
- {
- BYTE *pByte;
- LONG n;
-
- if( pDib == NULL )
- return;
-
- for( n=DibSizeImage(pDib), pByte = DibPtr(pDib); n > 0; n-- )
- *(pByte++) = ~(*pByte);
-
- }
-
- // SetCurrentHotspot() - Make the give hotspot the currently selected one
- //
- // Note: If pHotspot is NULL, there will be no currently active hotspot
- // upon return.
- void CSVViewerView::SetCurrentHotspot( CHotspot *pHotspot )
- {
- CRect rect;
-
- // It it's the same, don't need to go any further
- if( m_currentHotspot == pHotspot )
- return;
-
- // Clean up the last hotspot if there was one
- if( m_currentHotspot != NULL )
- {
- GetHotspotRect( &rect, m_currentHotspot );
- InvalidateRect( &rect, FALSE );
-
- if( !m_bEdit )
- {
- if( m_pHotspotDib != NULL )
- {
- PutImage( m_pHotspotDib, m_currentHotspot->Location(), m_currentHotspot->Size() );
- Invalidate();
- GlobalFreePtr( m_pHotspotDib );
- m_pHotspotDib = NULL;
- }
-
- if( m_pAlteredDib != NULL )
- {
- GlobalFreePtr( m_pAlteredDib );
- m_pAlteredDib = NULL;
- }
- }
- }
-
- // Make the new hotspot the current one
- m_currentHotspot = pHotspot;
-
- // It there is a new current hotspot make sure it force it
- // to get redrawn (will be redrawn in OnDraw with focus)
- if( m_currentHotspot != NULL )
- {
- GetHotspotRect( &m_rectTracker.m_rect, m_currentHotspot );
- InvalidateRect( &m_rectTracker.m_rect, FALSE );
-
- // This next line would copy the hotspot image to the clipboard
- // if you so desired
- // CopyImage( m_currentHotspot->Location(), m_currentHotspot->Size() );
-
- if( !m_bEdit )
- {
- HGLOBAL hDib;
- hDib = GetImage( m_currentHotspot->Location(), m_currentHotspot->Size() );
- if( hDib != NULL )
- {
- m_pHotspotDib = (PDIB)GlobalLock( hDib );
- hDib = GetImage( m_currentHotspot->Location(), m_currentHotspot->Size() );
- if( hDib != NULL )
- m_pAlteredDib = (PDIB)GlobalLock( hDib );
-
- if( m_pAlteredDib != NULL )
- {
- this->Alter( m_pAlteredDib );
- PutImage( m_pAlteredDib, m_currentHotspot->Location(), m_currentHotspot->Size() );
- Invalidate();
- }
- }
- }
- }
- else
- m_rectTracker.m_rect.SetRectEmpty();
- }
-
- // OnEditHotspot() - Edit the current hotspot
- afx_msg void CSVViewerView::OnEditHotspot()
- {
- if( m_currentHotspot != NULL )
- {
- CPSHotspot PSHotspot( this, (CSVViewerDoc *)GetDocument(), m_currentHotspot );
- PSHotspot.DoModal();
- }
- }
-
- // OnDeleteHotspot() - Delete the current hotspot
- afx_msg void CSVViewerView::OnDeleteHotspot()
- {
- CSVViewerDoc* pDoc = (CSVViewerDoc*)GetDocument();
- CHotspotList* pHotspots = pDoc->GetHotspotList();
- CHotspot* pHotspot;
-
- if( m_currentHotspot != NULL && m_bEdit )
- {
- CString string;
- pHotspot = m_currentHotspot;
-
- AfxFormatString1( string, AFX_MSG_DELETEHOTSPOT, pHotspot->GetName() );
- if( AfxMessageBox( string, MB_YESNO ) != IDYES )
- return;
-
- SetCurrentHotspot( NULL );
-
- pHotspots->Delete( pHotspot->GetID() );
- pDoc->SetModifiedFlag();
- }
- }
-
- // OnModeEdit() - Switch between Edit and Run mode
- afx_msg void CSVViewerView::OnModeEdit()
- {
- SetCurrentHotspot(NULL);
- m_bEdit = !m_bEdit;
- Invalidate();
- }
-
- // OnUpdateCurrentHotspot() - Update CCmdUI object based on presence of a current hotspot
- afx_msg void CSVViewerView::OnUpdateCurrentHotspot( CCmdUI* pCmdUI )
- {
- pCmdUI->Enable( this->IsViewPresent() &&
- m_bEdit &&
- m_currentHotspot != NULL );
- }
-
- // OnUpdateModeEdit() - Update CCmdUI object based on Edit mode
- afx_msg void CSVViewerView::OnUpdateModeEdit( CCmdUI* pCmdUI )
- {
- if( this->IsViewPresent() )
- {
- pCmdUI->SetCheck( (m_bEdit) ? 1 : 0 );
- pCmdUI->Enable( !m_bEdit );
- }
- else
- {
- pCmdUI->SetCheck(0);
- pCmdUI->Enable(FALSE);
- }
- }
-
- // OnUpdateModeRun() - Update CCmdUI object
- afx_msg void CSVViewerView::OnUpdateSave(CCmdUI* pCmdUI)
- {
- char drive[255], dir[255], fname[255], ext[255];
- _splitpath(((CSVViewerDoc*)GetDocument())->GetPathName(), drive, dir, fname, ext);
-
- if(((CSVViewerDoc*)GetDocument())->IsModified())
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
-
- // OnUpdateModeRun() - Update CCmdUI object based on Edit mode
- afx_msg void CSVViewerView::OnUpdateModeRun( CCmdUI* pCmdUI )
- {
- if( this->IsViewPresent() )
- {
- pCmdUI->SetCheck( (!m_bEdit) ? 1 : 0 );
- pCmdUI->Enable( m_bEdit );
- }
- else
- {
- pCmdUI->SetCheck(0);
- pCmdUI->Enable(FALSE);
- }
- }
-
- afx_msg void CSVViewerView::OnLButtonDblClk( UINT nFlags, CPoint point )
- {
- CHotspot* pHotspot;
-
- // If we don't have a view, bail
- if( !this->IsViewPresent() )
- return;
-
- // See if we have a Hotspot here
- if( ( pHotspot = PtInHotspot( point ) ) != NULL )
- {
- // Set the current hotspot...
- SetCurrentHotspot( pHotspot );
-
- // ...and edit it
- OnEditHotspot();
- }
- }
-
- afx_msg void CSVViewerView::OnLButtonDown( UINT nFlags, CPoint point )
- {
- CSVViewerDoc* pDoc = (CSVViewerDoc*)GetDocument();
- CHotspotList* pHotspots = pDoc->GetHotspotList();
- CHotspot* pHotspot;
- CRect rect;
- int id;
-
- // If we don't have a view, bail
- if( GetView() == NULL )
- return;
-
- if( !m_bEdit )
- return;
-
- // See if we have a Hotspot here
- if( ( pHotspot = PtInHotspot( point ) ) != NULL )
- {
- // Set the current hotspot
- SetCurrentHotspot( pHotspot );
-
- // Get current rect
- if( !GetHotspotRect( rect ) )
- return;
-
- m_rectTracker.m_rect = rect;
-
- // Let the user resize the rect (unless it's locked)
- if( !pHotspot->IsLocked() && m_rectTracker.Track( this, point ) )
- {
- SetHotspotRect( m_rectTracker.m_rect );
-
- // Mark the document as dirty
- pDoc->SetModifiedFlag();
-
- // Invalidate origional and resultant rects
- this->InvalidateRect( &m_rectTracker.m_rect, FALSE );
- this->InvalidateRect( &rect, FALSE );
- }
- return;
- }
-
- // See if we are going to create a new hotspot...
- //
- // Note: If the new hotspot is too small then the user
- // probably didn't want to make one, so don't.
- SetCurrentHotspot( (CHotspot *)NULL );
- m_rectTracker.m_rect.SetRect( point.x, point.y, point.x, point.y );
- if( m_rectTracker.TrackRubberBand( this, point ) &&
- m_rectTracker.m_rect.Height() > 10 &&
- m_rectTracker.m_rect.Width() > 10 )
- {
- pHotspot = pHotspots->Create( &id );
-
- SetHotspotRect( &m_rectTracker.m_rect, pHotspot );
- SetCurrentHotspot( pHotspot );
-
- // Bring up the dialog so the user can edit it
- CPSHotspot PSHotspot( this, pDoc, m_currentHotspot );
- if( PSHotspot.DoModal() == IDOK )
- {
- // Mark the document as dirty
- pDoc->SetModifiedFlag();
- }
- else
- {
- pHotspots->Delete( id );
- SetCurrentHotspot( (CHotspot *)NULL );
- }
- }
- }
-
- afx_msg void CSVViewerView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- }
-
- afx_msg void CSVViewerView::OnRButtonDown(UINT nFlags, CPoint point)
- {
- // Scroll the image until WM_RBUTTONUP message received
- ScrollImage( point, FALSE );
- }
-
- afx_msg void CSVViewerView::OnRButtonUp( UINT nFlags, CPoint point )
- {
- CSurroundView::OnRButtonUp( nFlags, point );
- }
-
- afx_msg void CSVViewerView::OnMouseMove( UINT nFlags, CPoint point )
- {
- if( m_bEdit )
- CSurroundView::OnMouseMove( nFlags, point );
- else
- SetCurrentHotspot( PtInHotspot( point ) );
- }
-
-