home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n08
/
sketchsc.exe
/
MYWIN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-01
|
3KB
|
108 lines
//-----------------------------------------------------------------------
// MYWIN.CPP: Various Windows support classes
//-----------------------------------------------------------------------
#include "stdafx.h"
#include "mywin.h"
#include <stdarg.h>
//-----------------------------------------------------------------------
int mapping_mode::mode = mapping_mode::MM_NONE;
//-----------------------------------------------------------------------
/*virtual*/ void device::prepare( void )
{
// If the owning window is a view, call it's OnPrepareDC
// function to set up the DC, otherwise just swap in the
// mapping mode. User can override this function to do
// other things if necessary.
ASSERT( owner );
if( owner->IsKindOf( RUNTIME_CLASS(CView) ) )
((CView *)owner)->OnPrepareDC( this );
else
SetMapMode( mapping_mode() );
}
//-----------------------------------------------------------------------
device::device(const CWnd *pWnd)
: owner ( pWnd )
, cursor ( 0, 0 )
, bounding ( 0,0,0,0 )
{
ASSERT( pWnd );
ASSERT( ::IsWindow(pWnd->m_hWnd) );
HDC hdc = ::GetDC( owner->GetSafeHwnd() );
if( !Attach( hdc ) )
AfxThrowResourceException();
prepare(); // User can get control of this virtual function
}
//-----------------------------------------------------------------------
device::device(const CDC *dc)
: owner ( NULL )
, cursor ( 0, 0 )
, bounding ( 0,0,0,0 )
{
// BUG: The docs claim that CDC::GetWindow() returns the
// window associated with a DC. The function isn't
// implemented, though, so we can't set owner to
// the window unless we create it in device(CWnd);
if( !Attach( dc->m_hDC ) )
AfxThrowResourceException();
}
/*virtual*/ device::~device()
{
if( owner )
{
ASSERT( m_hDC );
::ReleaseDC( owner->m_hWnd, m_hDC );
}
Detach();
}
//-----------------------------------------------------------------------
void device::invalidate_rect( CRect invalid_region,
int erase_background /*=TRUE*/ )
{
ASSERT( owner );
LPtoDP( &invalid_region );
((CWnd *)owner)->InvalidateRect( &invalid_region, erase_background );
}
//-----------------------------------------------------------------------
CRect *device::get_client_rect( CRect *r ) const
{
ASSERT( owner );
owner->GetClientRect( r );
DPtoLP( r );
return r;
}
//-----------------------------------------------------------------------
void device::set_up_scrolling( CSize document_size )
{
// Typically called from the document; document_size must
// not be passed in by reference---I'm modifying it. The
// document_size must be in logical units.
ASSERT( owner );
ASSERT( owner->IsKindOf(RUNTIME_CLASS(CScrollView)) );
LPtoDP( &document_size );
((CScrollView*)owner)->SetScrollSizes( mapping_mode(), document_size );
}
//-----------------------------------------------------------------------
const CPoint &device::puts( const CString &str )
{
TEXTMETRIC tm; /*=*/ GetTextMetrics( &tm );
int tab_separation = 8*tm.tmAveCharWidth;
CSize line_size = TabbedTextOut( cursor.x, cursor.y, str,
str.GetLength(),
1, // nTabPositions,
&tab_separation, // lpnTabStopPositions,
0 ); // nTabOrigin );
cursor.y += (line_size.cy + tm.tmExternalLeading);
return cursor;
}