home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////////
- //
- // CHotspot.cpp : Implementation of the CHotspot 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"
-
- #ifndef __CHOTSPOT_H__
- #include "CHotspot.h"
- #endif
-
- #ifndef __UTILITY_H__
- #include "utility.h"
- #endif
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CHotspot
-
- CHotspot::CHotspot( int id )
- {
- // Save hotspot ID
- m_id = id;
-
- // Set defaults
- m_name.Empty();
- m_location.latitude = 0;
- m_location.longitude = 0;
- m_size.cx = 0;
- m_size.cy = 0;
- m_bLocked = FALSE;
- }
-
- CHotspot::~CHotspot()
- {
- }
-
- HRESULT CHotspot::Write( LPSTREAM pIStream )
- {
- HRESULT hr;
-
- hr = WriteToStream( pIStream, m_name );
- hr = WriteToStream( pIStream, &m_location );
- hr = WriteToStream( pIStream, m_size );
- hr = WriteToStream( pIStream, m_bLocked );
- return hr;
- }
-
- HRESULT CHotspot::Read( LPSTREAM pIStream )
- {
- HRESULT hr;
-
- hr = ReadFromStream( pIStream, m_name );
- hr = ReadFromStream( pIStream, &m_location );
- hr = ReadFromStream( pIStream, m_size );
- hr = ReadFromStream( pIStream, &m_bLocked );
- return hr;
- }
-
- // CHotspotList
-
- CHotspotList::CHotspotList()
- {
- m_nextID = 0;
- }
-
- CHotspotList::~CHotspotList()
- {
- ResetContent();
- }
-
- // Create() - Create a hotspot
- CHotspot* CHotspotList::Create( int *id )
- {
- CHotspot* pHotspot = new CHotspot( m_nextID++ );
- Add( (CObject*)pHotspot );
-
- // See if they want the ID back
- if( id != NULL )
- *id = pHotspot->GetID();
-
- return pHotspot;
- }
-
- // Draw() - Draw all Hotspots in the hotspot list
- void CHotspotList::Draw( CDC *pDC )
- {
- int index;
- CHotspot *pHotspot;
- CRect rect;
-
- for( index = GetUpperBound(); index >= 0; index-- )
- {
- pHotspot = (CHotspot *)GetAt(index);
-
- if( pHotspot != NULL )
- {
- // rect = pHotspot->m_rect;
- // pView->DibToClient( &rect );
-
- // if( pDC->RectVisible( &rect ) )
- // pDC->DrawFocusRect( &rect );
- }
- }
- }
-
- // PtInHotspot() - Return the hotspot at the given point, if any
- CHotspot *CHotspotList::PtInHotspot( CPoint point )
- {
- int index;
- CHotspot *pHotspot;
-
- for( index = GetUpperBound(); index >= 0; index-- )
- {
- pHotspot = (CHotspot *)GetAt(index);
-
- if( pHotspot != NULL )
- {
- // if( pHotspot->m_rect.PtInRect( point ) )
- return pHotspot;
- }
- }
- return (CHotspot *)NULL;
- }
-
- HRESULT CHotspotList::Write( LPSTREAM pIStream )
- {
- int index;
- CHotspot *pHotspot;
- HRESULT hr;
-
- WriteToStream( pIStream, this->GetSize() );
-
- for( index = GetUpperBound(); index >= 0; index-- )
- {
- pHotspot = (CHotspot *)GetAt(index);
-
- if( pHotspot != NULL )
- {
- hr = pHotspot->Write( pIStream );
- if( FAILED(hr) )
- return hr;
- }
- }
-
- return S_OK;
- }
-
- HRESULT CHotspotList::Read( LPSTREAM pIStream )
- {
- int index, count;
- CHotspot *pHotspot;
- HRESULT hr;
-
- ResetContent();
-
- // Read number of hotspots
- hr = ReadFromStream( pIStream, &count );
- if( FAILED(hr) )
- return hr;
-
- for( index = 0; index < count; index++ )
- {
- pHotspot = Create();
- hr = pHotspot->Read( pIStream );
- if( FAILED(hr) )
- {
- delete pHotspot;
- return hr;
- }
- }
-
- return S_OK;
- }
- // ResetContent() - Delete all Items in the list
- void CHotspotList::ResetContent()
- {
- int index;
- CHotspot* pHotspot;
-
- for( index = GetUpperBound(); index >= 0; index-- )
- {
- pHotspot = (CHotspot*)GetAt(index);
-
- if( pHotspot != NULL )
- delete pHotspot;
- }
- RemoveAll();
- }
-
- // IsValidEntry() - Is the given object in the list
- BOOL CHotspotList::IsValidEntry( CHotspot* pHotspot )
- {
- int index;
-
- for( index = GetUpperBound(); index >= 0; index-- )
- {
- if( pHotspot == (CHotspot *)GetAt(index) )
- return TRUE;
- }
-
- return FALSE;
- }
-
- // Delete() - Delete Item given it's ID
- //
- // NOTE WELL: All indexes in the list change after calling this function
- // But this doesn't matter as we use the ID anyway
- //
- void CHotspotList::Delete( int id )
- {
- int index;
- CHotspot* pHotspot;
-
- if( ( index = GetIndexFromId( id ) ) == -1 )
- return;
-
- pHotspot = (CHotspot *)GetAt(index);
- RemoveAt( index );
- delete pHotspot;
- }
-
- CHotspot* CHotspotList::GetById( int id )
- {
- int index;
- CHotspot* pHotspot;
-
- for( index = GetUpperBound(); index >= 0; index-- )
- {
- pHotspot = (CHotspot*)GetAt(index);
-
- if( pHotspot != NULL )
- if( pHotspot->m_id == id )
- return pHotspot;
- }
-
- return (CHotspot*)NULL;
- }
-
- CHotspot* CHotspotList::GetByIndex( int index )
- {
- if( index < 0 || index > GetUpperBound() )
- return (CHotspot*)NULL;
-
- return (CHotspot*)GetAt(index);
- }
-
- int CHotspotList::GetIndexFromId( int id )
- {
- int index;
- CHotspot* pHotspot;
-
- for( index = GetUpperBound(); index >= 0; index-- )
- {
- if( ( pHotspot = (CHotspot*)GetAt(index) ) != NULL )
- {
- if( pHotspot->m_id == id )
- return index;
- }
- }
-
- return -1;
- }
-
- int CHotspotList::GetIdFromIndex( int index )
- {
- CHotspot* pHotspot = GetByIndex( index );
- if( pHotspot != NULL )
- return pHotspot->GetID();
-
- return -1;
- }
-